Punching the clock at odd hours might mess up your mind: Shift workers show more signs of cognitive impairment than those who work normal hours do, a new Swedish study found.

The researchers found that people who work outside the 9 to 5 range—and those who had done so within the last 5 years—took more time to complete a test that measured brain function and aging than people who never worked shift work or who did so more than 5 years ago. 

Related: Has Your Brain Already Peaked?

Working extremely early or late hours—as is necessary in lots of healthcare, public safety, and food service jobs—disrupts your brain’s frontal lobe, the part responsible for things like motor control, memory, language, judgment, and problem-solving, says lead study author Christian Benedict, Ph.D.

It also messes with your body’s biological clock, which makes it harder for you to fall asleep and stay asleep.

That means your shuteye is neither long nor deep enough to fully restore your body and brain, which can put you at risk of learning and memory impairments, he says. 

Related: The Better Man Project From Men’s Health—2,000+ Awesome Tips on How to Live Your Healthiest Life 

The longer you’ve been employed in shift work, the worse its effects on your brain. 

The good news is, switching to normal hours now can help stop the damage. The study suggests that 5 years after switching off shift work, your performance on the brain test will be just as good as someone who’s never worked odd hours. 

But if you’re unable to change to a 9 to 5 shift, you can try to counter the effects by making sure to optimize your shuteye.

Related: 5 Ways to Sleep Better Every Night

That means snoozing for at least 7 hours a night, and sticking to a regular sleep routine—even during your days off—so your body knows when it should transition from wakefulness to sleep, Benedict says.