IF YOUR COMPANY is one of those hip and cool joints that has a foosball table in the break room, allows you to customize your cubicle, and loads up the kitchen with all sorts of treats, well, congratulations. But you probably also gained 10lbs when you got hired because of all of the new work stress and easy access to sugary snacks. All of that pressure to perform can also cause you to eat unhealthy fare at dinner—says a new study published in the Journal of Applied Psychology—but simply getting a good night’s sleep may curb junk food binges the next day.

Researchers investigated 235 workers via two studies in China—one on IT employees with high workloads, and another on call-center workers stressed out from dealing with customers—and found that the stressful environments led them to a bad mood, which was then linked to unhealthy eating after work.

“Eating is sometimes used as an activity to relieve and regulate one’s negative mood, because individuals instinctually avoid aversive feelings and approach desirable feelings,” said study co-author Yihao Liu, assistant professor at the University of Illinois. “Second, unhealthy eating can also be a consequence of diminished self-control. When feeling stressed out by work, individuals usually experience inadequacy in exerting effective control over their cognitions and behaviors to be aligned with personal goals and social norms.”

But they also discovered that when the workers slept better the night before they were better able to handle the stress of the following day, and didn’t go for the crappy food as often for their dinner. “A good night’s sleep can make workers feel replenished and vigorous again, which may make them better able to deal with stress at work the next day and less vulnerable to unhealthy eating,” said Liu.

To get your best night’s sleep, take some tips from the National Sleep Foundation and stay on a regular schedule, make sure to exercise daily, keep your room at a cool temp, stop using digital devices before bed, and avoid alcohol and caffeine in the evening.