Yes, workplace stress is doing a number on your weight. But a good night’s sleep can get you back on track.

A new Michigan State University study published in the Journal of Applied Psychology this week is one of the first to connect the dots between job stress, junk food and catching Zs.

Read this: You have to try this scientist’s technique for falling asleep faster 

Researchers followed 235 workers at two business: a Chinese information technology company where overworked employees felt there was “never enough time in the day,” as well as a call center where staffers were stressed from dealing with “rude and demanding” customers.

The study linked stress at both workplaces with the employees experiencing a bad mood on the job, which in turn shaped unhealthy eating once they were off the clock.

“We found that employees who have a stressful workday tend to bring their negative feelings from the workplace to the dinner table, as manifested in eating more than usual and opting for more junk food instead of healthy food,” wrote study co-author Chu-Hsiang “Daisy” Chang, an associate professor of psychology.

Hey, who hasn’t ordered comfort food off of Seamless or knocked back happy hour drinks to cheer themselves up after a bad day at work? Research shows that we self-medicate with fatty, high-calorie foods. Worse, a 2014 study found stress eaters burned 104 fewer calories on average than non-stressed women each day, so all of that comfort food is getting comfortable around your waistline.

Read this: Here’s a scary new reason to stop drinking diet soda 

But the good news is, the Michigan State University study also found that getting a solid night’s rest helped employees handle their stress better the next day, and better protected them from hitting the vending machine over the salad bar.

“A good night’s sleep can make workers replenished and feel vigorous again, which may make them better able to deal with stress at work the next day and less vulnerable to unhealthy eating,” wrote Chang.

Read this: Here’s how much shut-eye Donald Trump, Jennifer Lopez and Marissa Mayer get 

That backs the growing body of research reminding us to catch more Zs. Lack of sleep costs the U.S. economy $411 billion in lost worker productivity, and Americans spend more than $40 billion on sleep aids.

Plus, a 2011 American Heart Association report found that women who got only four hours of sleep at night ate 329 more calories the next day than they did after they slept for nine hours. Men ate 263 more calories.