If you’ve ever had to pull yourself together after a breakup and figure out a way to process the pain, a new study may help you out. Dwelling on a breakup for a while can help you work through the heartache more effectively and find some distance.

The trick, of course, is to think through the breakup in a healthy way, rather than obsessively, since obsession can make things worse instead of better.

The new study asked half of a group of 200 people who had experienced a non-marital breakup in the last six months to talk in detail about their breakups, by both speaking into a voice recorder and by writing about it. They asked the other half of the participants to do just a fraction of this introspection.

At the end of the nine-week study period, the researchers had the participants fill out questionnaires about their well-being and psychological health.

It is particularly helpful to write as if you were telling the story to a stranger, rather than to a close friend.

People who’d spent the greater amount of time talking and writing about their breakups were better off psychologically — in particular, they had been more successful at detaching themselves from the person they were with and regained a sense of autonomy, or self-sufficiency. It’s not an easy or pain-free process to manage, but the results show that it can be helped along by reflecting on the breakup in writing or by talking.

“The process of becoming psychologically intertwined with the partner is painful to have to undo,” study author Grace Larson said in a news release. “Our study provides additional evidence that self-concept repair [spending the time to fully process the loss and reorient yourself] actually causes improvements in well-being.”

How the connection works isn’t entirely clear, but it may be that talking and writing creates a narrative, which lets you wrap your head around the new situation. As Larson says, “It might be simply the effect of repeatedly reflecting on one's experience and crafting a narrative — especially a narrative that includes the part of the story where one recovers.”

Writing in a journal can be a big positive following a difficult breakup. It is particularly useful, Larson says, to write as if you were telling the story to a stranger, rather than to a close friend.

Talking with a close friend may run the risk of becoming griping, and running the breakup in an endless loop in your head without writing it down may become the type of rumination that can lead to depression.

The main goal is to try to recover your sense of self, as separate and removed from the person you’ve broken up with.

“The recovery of a clear and independent self-concept seems to be a big force driving the positive effects of this study, so I would encourage a person who recently experienced a breakup to consider who he or she is, apart from the relationship,” said Larson.

Think of all the aspects of yourself that you may have forgotten while in the relationship, and remember that you can now focus on them again. Even though breakups may hurt, getting to know yourself again is always a good thing.

The study was carried out by a team at Northwestern University and published in Social Psychological and Personality Science.