This was not your best week. Something didn’t go right. Let’s say it was a negotiation that didn’t play out your way.

What do you do afterward? You might go to a bar with friends, talk to your spouse, or call your mom. But those are just delay tactics. Soon the ruminating will begin. You’ll wonder what went wrong and blame yourself, others, or external factors. When that becomes exhausting, you’ll tell yourself that you need to forget the past and focus on what’s ahead.

This is a natural and perfectly reasonable reaction, but it’s psychologically painful without much benefit. It won’t prevent you from experiencing the same kind of failure a second or third or fourth time.

There is a better way: a mental protocol through which you ask yourself a series of brief, structured questions and put some effort into answering them. Based on new research on counterfactual thinking (which is exactly what it sounds like: imagining alternatives to what just happened), this process is not difficult, and it promises to both ease the pain of the setback and position you to do better next time.

Counterfactual thinking is something most of us do all the time — “If I hadn’t bumped into my old friend last year, I would have missed out on getting this great job with his company!” or “If only I had said yes to that overseas assignment, I probably would have been promoted.” But researchers are now categorizing it into different types and determining why we use them and when. There’s still a lot to be learned, but studies suggest that certain forms of counterfactual thinking can be particularly helpful when people need to recover and improve performance after negative events.

Let’s come back to that just-concluded, unsuccessful negotiation. Your company is trying to be more agile in the face of changing customer demand, and you had asked an important supplier to leave the working agreement more open-ended than usual so you would have the ability to change course during the year. His only concession was to make it a six-month agreement, rather than 12-month, and you and your boss consider this a pretty significant failure.

You avail yourself of a couple of the usual recovery activities listed above. You beat up on yourself for being incompetent and unlucky. You blame the stiff who represented the supplier, as well as those dry turkey sandwiches that the caterer provided. “Ah well,” you say as you drain your beer with a colleague, “lessons learned. Time to move on.”

But actually no lessons have been learned, and it’s not time to move on. Not yet.

Instead, follow these five steps, in order:

Imagine a better outcome, Part 1. Challenge yourself to conceive of an upward counterfactual, a path that might have led to a better deal. Make sure to focus on your own actions, not someone else’s. For example, your counterpart had seemed close to agreeing to several of your suggestions on flexibility, but then you both took a break. Afterward, he was more adamant. Maybe if you had pressed for an answer before the break, the outcome would have been better. Imagine a better outcome, Part 2. Challenge yourself to think of yet another upward counterfactual. Why? The idea is to combat your natural tendency to fixate on the first alternative scenario as the only one, a trap known as hindsight bias. The apparent obviousness of the first alternative, now that you’ve thought of it, induces overconfidence; you begin to feel as though you were aware of it all along. Imagining a second path to a better outcome helps you to avoid attributing your failure to a simplistic, pat reason. As an example of a second scenario, imagine that you put the flexibility issue on the table at the beginning of the negotiation. Would that have yielded a better outcome than springing it on your counterpart later in the talks, as you did? Imagine a different path leading to the same outcome. This is known as semifactual thinking, or an “even if.” For example, breaking the negotiations into two distinct talks with different counterparts — the first talk being about price and the second about nonprice terms, for example — would have been a very different experience, but it might have led to the same outcome. Next, ask yourself why the outcome might have been the same. In this case, was it because there is widespread worry among the supplier’s staff that the marketplace is shifting rapidly, and they’re afraid to allow any contract change that might hurt their position? The purpose of this step in the failure and recovery process is to reveal obstacles you might not have noticed or articulated. Later on, you can circle back and try to figure out how to overcome them. For example, it might be possible to allay the supplier’s anxiety by offering something else as potential compensation, such as an option to raise prices during the life of the contract. Imagine the same path leading to a different outcome. Think of how a different outcome — better or worse — could have resulted from the same process you followed. Picture your counterpart smiling and saying yes to your suggestion about flexibility. Or frowning and insisting on no changes at all to the contract’s length. One purpose of this step is to highlight the randomness in outcomes. In most cases, the reality is that the very steps you took could have led to different endpoints. People have trouble accepting that. If you’re going to recover effectively, it’s important to maintain a healthy respect for outside forces. This step can also help you think about backup and contingency plans to cope with these forces. Imagine a worse outcome. This downward counterfactual is partly a feel-good tactic. Think of a different path that might have led to a poorer result, and then pat yourself on the back for having avoided it. But there’s another purpose to this step: to broaden your understanding of what just happened. Let’s say you thought about making, but then didn’t make, a comment about your counterpart’s declining sales. The idea would have been to underscore that his company doesn’t have a good grasp of what’s going on in the marketplace, but you realized in the nick of time that the comment might have put him on the defensive and made things worse. Pursue that idea a little further and you might end up with a big-picture understanding of the supplier’s present sense of vulnerability.

By completing these five steps, you avoid blame and bias and other kinds of mental ruts, and you see an enlarged, nuanced picture of the failure. You’re better positioned to know what really did and didn’t cause the setback. And the upward counterfactuals give you a starting point for planning the next go-round and improving your subsequent performance. You may not follow your imagined scenarios precisely, but you’ve learned to stretch your mind to incorporate new possible tactics.

I’ve seen this method work for managers and entrepreneurs in various contexts. The links between counterfactual thinking and interpersonal effectiveness are underscored by research on schizophrenia, which demonstrates that an inability to do the former partly explains patients’ social dysfunction. Neuroimaging studies suggest that since counterfactual thinking happens in the same part of the brain as planning, it might serve as a sort of interface between emotional thinking and goal setting.

Leaders are often told to maximize their “return on failure,” but so far there has been little focus on the specific steps one should take to learn from mistakes. Challenging yourself to use counterfactual thinking and formulate detailed alternative scenarios is one way to bridge that gap and ensure you do better the next time around.