Understanding how thoughts flow from one to the next could offer a look into the minds of people with different mental illnesses.

That’s the idea behind a study on “mind-wandering” in Nature Reviews Neuroscience, which looks at how thoughts move and change when the mind is active and when it is at rest. The researchers reviewed literature on neuroscience from numerous journals and explain that the interaction of different brain networks is key to how thoughts flow. “Mind-wandering is best understood as a member of a family of spontaneous-thought phenomena that also includes creative thought and dreaming,” according to the study, which was led by University of British Columbia staffers.

But that spontaneous movement can be derailed within the mind by both automatic constraints such as obsessive thoughts and deliberate constraints like goal-directed thought. “This dynamic framework can shed new light on mental disorders that are marked by alterations in spontaneous thought, including depression, anxiety and attention deficit hyperactivity disorder.”

Mind-wandering is more than just thoughts straying from what a person is doing, lead author Kalina Christoff said in a statement from the University of British Columbia. “Sometimes the mind moves freely from one idea to another, but at other times it keeps coming back to the same idea, drawn by some worry or emotion. Understanding what makes thought free and what makes it constrained is crucial because it can help us understand how thoughts move in the minds of those diagnosed with mental illness.” And spontaneous movement of thought is necessary for dreaming and creative thinking.

Each person’s thoughts have their own rhythm, but the minds of people with mental illnesses can move in a way that’s a more extreme version of that normal rhythm — naturally occurring constraints that affect thought are amplified. Study co-author Zachary Irving from the University of California, Berkeley, who has ADHD, said in the statement, “We all have someone with anxiety and ADHD in our minds. The anxious mind helps us focus on what’s personally important; the ADHD mind allows us to think freely and creatively.”

Source: Christoff K, Irving ZC, Fox KCR, Spreng RN and Andrews-Hanna JR. Mind-wandering as spontaneous thought: a dynamic framework. Nature Reviews Neuroscience. 2016.