If your kid is having trouble sleeping, take a closer look at what he’s been watching on TV. A new study published in the journal Pediatrics finds that violent or age-inappropriate programming could increase the odds that children have problems falling asleep and staying asleep or have nightmares.

Previous studies have consistently linked media use to disrupted sleep and behavioral problems in kids, but it’s never been clear whether the association was causal — that is, whether TV viewing led to kids’ problems, or vice versa — or whether changing what kids watched would have any impact on improving their sleep habits. The new study by researchers at the Seattle Children’s Research Institute sought to answer that question.

Lead study author Michelle Garrison and her colleagues looked at the sleeping and TV-watching habits of 565 kids aged 3 to 5 years. The families were randomly assigned to one of two groups: one group was coached in person, by phone and through mailings on how to make better media choices for their kids; they were encouraged to replace violent or mature content — which could include seemingly harmless cartoons like Bugs Bunny that may be funny for older kids, but inappropriate for younger ones — with preschool-age-appropriate educational or prosocial shows like Curious George, Dora the Explorer and Sesame Street. Parents were also encouraged to watch and discuss TV shows with their kids. The control group received only mailers about nutrition.

The goal of the study wasn’t to limit overall media exposure, just exposure to a particular type of content. “Making a relatively simple change in what kids are watching is a change worth the effort,” Garrison told HealthDay. “Sometimes parents feel overwhelmed by the idea of getting rid of TV altogether, but switching shows can make a big difference.”

How big? Researchers assessed children’s sleep quality by using portions of a standard questionnaire measuring how often kids have trouble falling asleep, their nightmare frequency, how many times they wake up during the night, their difficulty waking up in the morning and how tired they are during the day. The questionnaires were administered at the start of the study and again at 6, 12 and 18 months. At the start of the study, there weren’t any significant differences between the two groups in terms of sleep problems or TV habits. The most common problem kids had was trouble falling asleep, with 38% of kids taking more than 20 minutes to fall asleep at least a couple of nights a week.

After the TV-show-swapping intervention, the frequency of sleep problems dropped, with kids watching age-appropriate shows experiencing 64% lower odds of any sleep problem compared with kids in the control group. The effect lasted about a year, but by 18 months many of the youngsters’ sleep problems began to reappear, which the authors attribute to parents becoming lax again about their kids’ media choices after the study.

What’s appropriate or inappropriate for a preschooler may not be immediately obvious to some parents. One thing to remember is that young children may not understand the concept of pretend. “An 8-year-old can watch superheroes and understand that it’s not what happens in real life,” Garrison told HealthDay. “But the same content can be overwhelming and scary for a 3-year-old. The idea that people might just explode is scary for a 3-year-old.”

That’s why watching violent TV can lead to nightmares and fears of monsters hiding in closest or under the bed — especially if the TV viewing happens in the hour before bedtime. In a previous study, also published in Pediatrics, Garrison and colleagues found that kids who used media (any TV or video games) around bedtime were more likely to have sleep problems than kids who abstained. Kids should be winding down before bedtime — perhaps by reading or playing with a toy — Garrison said, but “TV and video games may interfere with that process by overexciting kids and ‘amping up’ their brains.”

Experts recommend that TV and other media should be avoided during the hour before bedtime (that goes for adults too), but if your kids are watching TV before nodding off, make sure they’re tuning into an age-appropriate show. Checking out media watchdogs like Common Sense Media can help parents figure out what kinds of programming they should steer clear of.