We all know that women outlive men. But there’s some good news for XYs: since the 1970s, the gender gap in life expectancy has shrunk. Now, a study released Monday in Proceedings of the National Academy of Sciences explains a major reason why. Surprisingly, the answer has little to do with eating fewer Big Macs. Since the 1970s, more baby boys are surviving birth in the first place.

The study authors analyzed more than 250 years of mortality data from 15 developed countries. Turns out that in 1751, males were only 10 percent more likely to die at birth than females. But that disadvantage increased until its peak of 30 percent around 1970. Since then, remarkably, it has declined.

Why? First off, males draw the short straw at the start. One reason is that baby boys’ immune systems can’t thwart infections as well as girls’ can. Boys are also more likely to be born premature and suffer early respiratory distress. Their bigger body and head sizes also make them harder to deliver.

Before germ theory took hold in the 1870s, the authors explain, the leading cause of infant death was infectious diseases. As sterile practices and other medical improvements gained traction in the twentieth century, the leading cause of death shifted to childbirth complications. But since the 1970s more babies have been born by C-section, and neonatal ICUs are on the rise. These medical advances are disproportionately helping the more vulnerable males.