Whenever I see a patient with insomnia, one of the first things I do is give the patient an informal pop quiz that consists of one question: “When you think of your bed, what’s the first thing that comes to mind?”

More times than not, patients with insomnia don’t give me an answer immediately. They typically think about it and then usually give me answers such as “rest, tossing and turning, lying there, frustration, worry.” This is so incredibly telling to me since the ideal answer should be “Sleep!”Once I reflect back to the patient that he or she didn’t say “sleep” as the first answer, patients are usually pretty surprised.

The reason for this is based on classical conditioning theory. That’s right, the same theory involving Pavlov’s dog that you may have learned about in college Psychology 101. When good sleepers go to sleep at night, their brains say “bed=sleep.” Essentially, the bed is “paired”—to use classical conditioning speak—with sleep. Whenever a good sleeper gets in bed, there’s an automatic signal sent that says it’s time to go to sleep.Once insomnia starts, however, more time is spent lying in bed awake, worrying, being frustrated and in some cases, watching TV and using computers or phones. After a few weeks of introducing these other behaviors into the bed during times when you’re supposed to be asleep, the pairing of “bed to sleep” begins to weaken and the bed now becomes paired strongly with whatever “awake” behaviors are being done in bed. So now, instead of signaling “sleep,” the bed signals “awake.”

The most powerful example of this occurs whenever I hear a patient say he or she is so sleepy on the couch watching TV at night, but that when he or she gets into bed shortly afterwards, the “sleep is gone” and the patient is wide awake in bed, thinking or watching TV. Again, the bed is now paired—whether you like it or not!—with “awake.” The more time you spend in bed lying awake with insomnia, the worse the insomnia gets.So how does someone with insomnia fix this problem? One of the most common treatment recommendations was developed by Richard Bootzin, Ph.D., in the 1970s, called “stimulus control.” It has lots of research support behind it and is considered a standard treatment for chronic insomnia. Stimulus control refers to controlling the stimulus—which is the bed, in this case—for sleep only. Stimulus control is really simple in theory, but difficult to do. The bed is solely for sleep and sex. That’s it.

And in general, it’s good to be aware of four things not to do in bed:

1. Don’t just lie there. If you’re lying in bed for more than 20 minutes, get up, go somewhere else—ideally, outside the bedroom if possible, but at least out of the bed if you’re in a studio apartment—and do something quiet, calm and relaxing in dim light.

2. Avoid electronics. Don’t use anything with screens (e.g. computers, tablets, TV) before bed, in bed or if you have to get out of bed because you can’t sleep. Just go old school and read a book, magazine or do a relaxing hobby that passes the time without focusing on being awake. The only caveat I have is to ballpark this activity once 20 minutes have passed; see why I say to ballpark it below.

3. Stop checking what time it is. I don’t recommend you look at a clock waiting for 20 minutes to pass before getting out of bed or back into bed since I frown upon any clock watching in the middle of the night. Instead, when you’re lying in bed and realize you haven’t fallen asleep yet and are getting frustrated or having a very active thought process, that’s the sign it has been about 20 minutes and it is time to get out of bed.

4. Don’t return to bed until you’re sleepy. And if you get back in bed and don’t fall asleep, get up and do the whole process again. There might even be a night or two here and there when you’re just sitting up outside the bed and never get to sleep that night. It’ll happen, but the more you get back in bed and just lie there, the more you weaken the association between “bed” and “sleep.” Stick with it!Stimulus control is extremely effective for many patients who suffer from chronic insomnia. However, if you have the occasional night of poor sleep, sticking with stimulus control can help prevent chronic insomnia in the future. As I say to all of my patients, short-term pain, e.g. getting out of bed at 2 a.m. when you’re tossing and turning, will bring about long-term gain—better sleep!