If you’ve ever had surgery where you were put under, you’ve probably been terrified to wake up in the middle of it, as the doctors are cutting into whatever part of you required surgery. It’s a terrifying experience, according to the people who’ve lived it: Some have felt the pain but couldn’t do anything about it. Well, now there may be a method that helps doctors determine whether or not you’re awake before they start cutting.

Anesthesiologist Alex Proekt and his team wanted to see if the stability of brain activity had anything to do with whether or not a person awakes during surgery. For their experiment, the team used four monkeys and placed grids of electrodes directly on the monkeys’ brains to record activity as the monkeys fell asleep under one of two common anesthetics. They then used computer modeling based on dynamical systems theory to see how stable the brain activity was.

According to the theory, stable brain systems respond to changes by returning to the baseline state, while unstable systems go crazy. When awake the monkeys were between stability and instability. When the researchers put the monkeys under the anesthesia, the activity of the brains became much more stable.

In a study conducted this past April, scientists found that small bursts of brain stability, in which activity is steady for hundreds of milliseconds, allow us to consciously perceive something. Proekt and his team have evidence that suggests if this balance goes on for too long, we lose consciousness. On the other end of the spectrum, if the bursts are too far apart, we may also lose consciousness.

“Together, the studies illustrate the delicate balance of the conscious brain,” Aaron Schurger of the Swiss Federal Institute of Technology in Lausanne, who did the earlier work, told New Scientist. “The system is pushed toward the boundary between stability and instability so that it can perform a delicate dance from one state to another.”

Currently, doctors use EEG monitoring and other methods to determine if a patient is awake during surgery or not. However, depending on the depth of the anesthesia, the monitors may not be able to pick up everything. And it doesn’t work on all types of anesthetics. Proekt believes that being able to monitor, record, and test the stability of brain activity in real time will allow anesthesiologists to more accurately assess the consciousness of their patients and keep said patients under for the required amount of time.