Not getting enough sleep may lead to sexual dysfunction in some populations, according to new research.

A recent study published in the Journal of Sexual Medicine followed nearly 4,000 men and women in their early- to mid-60s for a year and found that poor sleep was associated with erectile dysfunction for men, and arousal problems and orgasmic difficulty for women. True, these were older folks, who are more likely to suffer from sleep apnea (a known culprit for an unhealthy sex life), and overall health issues that might impact their slumber.

But sleep apnea is on the rise in younger generations — especially in men — and guess what, guys? No matter what your age, a lack of sleep impacts your levels of testosterone. Low levels of testosterone can lead to a lack of sexual desire and erectile dysfunction.

Here’s how those are connected: It turns out that your highest levels of that important hormone occur during REM sleep, which is the deep, healing sleep that occurs late in the sleep cycle. Your first REM will last about 10 minutes, but as the night goes on REM stages grow longer, with the final one lasting up to an hour. So, if you don’t sleep long enough to enter REM sleep, you don’t get those restorative levels of circulating testosterone.