Who doesn’t remember their first caramel apple at a fall fair, or trying to decide between the plain variety and the nut-studded kind?

But these sweet, sticky concoctions can be breeding grounds for bacteria. In 2014, an outbreak of food poisoning from listeria linked to caramel apples resulted in seven deaths and 35 illnesses, according to the Centers for Disease Control and Prevention.

Now researchers have solved the mystery of why the chewy treats are susceptible to contamination — which can help you and your kids avoid food poisoning this Halloween.

In their paper, published in the medical journal mBio , the researchers explained that scientists were puzzled because apples are too acidic for listeria to grow rapidly. And the bacteria doesn’t usually grow on caramel due to its low water content.

Related: Soft Cheeses and Spreads Recalled for Potential Listeria Contamination

To figure out what was going on, they did a simple experiment. They whipped up a bacteria cocktail consisting of the listeria strains associated with or closely matching those in the 2014 outbreak. Next, they coated Granny Smith apples with it. They then punctured half of the apples with sticks and dipped all the apples in caramel. The scientists then stored the apples for a month at room temperature or in a refrigerator.

Can you guess which apples had the most listeria growth? If you picked the ones with the sticks, you’re right. Temperature also played a role: The refrigerated apples without sticks had zero listeria growth.

Stored at room temperature, caramel apples without sticks took 11 days to grow a significant amount of bacteria. In apples with sticks, bacteria grew 1,000-fold in just three days.

Refrigeration slowed but didn't stop bacteria growth in apples with sticks. The refrigerated apples with sticks showed no listeria growth during the first week, but over the next few weeks, some listeria cropped up. After 28 days, the difference was statistically significant.

Related: Stomach Flu Symptoms: Is it a Virus or Something Else?

Why were the apples with sticks such a hotbed for rapid listeria growth? Jamming a stick into an apple allows a little apple juice to trickle onto the caramel coating — and provide bacteria an inviting place to set up shop, the researchers explained.

The moral of the story? To be on the safe side, think twice about indulging in the caramel apples at fairs and farmers markets. Opt instead to make your own at home — and enjoy them immediately.

Diana is an award-winning writer and editor with more than 20 years' experience in magazine, video, book and digital journalism, with a specialty in health coverage. She was a longtime writer and news editor at the Center for Investigative Reporting; has written for publications from the Washington Post to the Times of London syndicate; and has served as a senior and/or consulting editor at Time Inc. Health, Hippocrates, HealthDay News Service and Reporting on Health. She was also editor in chief of Consumer Health Interactive, a national health and medical web site, and has reported on finance for Blueshift Research and PBS Frontline. Before joining SafeBee, she was editor of Bioenergy Connection, a national magazine about bioenergy at UC Berkeley. Her favorite safety tip: Wear a bike helmet.