This story has been updated. It was originally published on June 8, 2017.

If you subscribe to Netflix, Amazon Prime, or any other streaming service, you’ve probably been there: Gazing at the screen as episode after episode autoplays, until you check the clock and realize just how late it is. After all, series like Stranger Things are seriously good television—so where’s the harm?

The problem is that a growing body of evidence suggests the various demands of a modern-day lifestyle, including late-night video binging, are seriously disrupting human sleep patterns—which can damage our overall health. But just try telling people to give up their Netflix—it’s a recipe for failure.

With that in mind, the American Academy of Sleep Medicine, a professional society founded in 1975, has taken it upon itself to set out some guidelines for enjoying top-notch shows while making sure your body and brain get enough rest. We can show you how to implement them.

Take breaks between episodes

The AASM recommends getting out of “the auto-play loop,” where you just watch episode after episode because it takes less effort than stopping the playback. Luckily, Netflix, Hulu, and other streaming services give you the option to turn auto-play off. The idea is that manually loading the next episode can prevent you from gluing your eyes mindlessly to the screen. However, it’s still easy for you to click, click, click through the episodes. Which is why you should also…

Set an episode limit

Don’t fire up the Orange is the New Black and then wait to see how the evening goes. Decide in advance how much you’re going to watch before bed and then stick to that limit, regardless of cliffhangers. (By the way, this is the same principle you should use for a night of boozing.)

If you have trouble obeying this type of limit, you might have to trick yourself. One way to do this is by downloading episodes onto your phone. Because Netflix and other services support offline downloads for many shows, you can pre-load all the television you’ve decided to watch in advance. Then put your phone in airplane mode to stop yourself from exceeding your limits. This download ability also lets you catch up with Bridgerton on the subway ride to work, instead of staying up watching it the night before.

The Netflix user interface for the show Bloodline, showing offline download options.
Downloading episodes can help you stick to your limits. David Nield

Stressed about finishing an episode on your commute? Try reserving some daylight hours when you’ll be able to watch without worrying about missing your stop or blowing past your bedtime. The AASM advises you to ease the binge-watching pressure by setting aside relaxed viewing time over the weekend.

[Related: How to add subtitles to Netflix and other apps]

Avoid using your phone in bed

Sure, few places provide a comfier binge-watching setting than your bed. But again, it’s all too easy to keep watching for one more episode when you and your phone are cozily tucked in. Using screens in bed can keep your mind active for longer than is healthy—so keep the gadgets away from your sleeping area.

Another problem with phones is that their glowing displays strain our eyes. All that staring at your phone is unhealthy, and one way to limit its impact on your sleep patterns is to watch on a bigger, more distant screen instead. So instead of using your phone in bed, try streaming that media to a television.

Control the light

Bright blue light, like the wavelengths emanating from your video screen, will keep you alert and suppress the chemicals supposed to send you to sleep. To make sure you’re able to drop off when you want to, you should stop binge-watching about half an hour before your desired bedtime. In fact, the AASM recommends turning off all screens at least 30 minutes before you sleep.

[Related: There’s a lot to learn about how blue light affects our eyes]

In fact reducing any blue light exposure after sunset could help steady your sleep cycle. So you should try cutting down on the amount of blue light your smartphone or laptop emits—and yes, there’s an app for that. Several apps, in fact.

The Night Shift option on an Apple iPhone with iOS.
Use Apple’s Night Shift option to get ready for bed. David Nield

For iPhone users, there’s a blue-light-reduction feature called Night Shift built right into iOS. It can automatically adjust the color of the screen during evening hours so that the display will emit reddish rather than bluish light. To find it, open the Settings app and then head to Display & Brightness.

Apple has also included the same feature in macOS. To set it up on your computer, open the Apple menu, choose System Preferences, and open the Displays dialog. Under the Night Shift heading on the right, you can set the color change schedule and strength as necessary, just as on iOS.

Android phones have a similar feature called Night Light. To activate it, go to SettingsDisplay, and tap on Night Light. You can schedule a daily start and end time, and customize the intensity by dragging the slider.

The AASM recommends adults sleep seven hours or more per night. Anything less than that can cause problems with work or school performance, cognitive abilities, and mood. You don’t need to give up your binge watching to reach this goal, but these tips should let you get a handle on your viewing habits—and make you feel a lot better.