Money can’t buy you love. But when love goes wrong, it can be very expensive.

Planning for a financially independent life is probably the last thing on your mind when your marriage is headed for a breakdown. But to rebuild your life, you’ll need to make sure your finances are in order.

You won’t want to be stressing about making your mortgage payments, affording groceries or saving for retirement when you’ve got so much else to cope with.

By keeping your ducks in a row before you and your spouse split, you’ll be more able to deal with all the tough money stuff that will be coming your way.

Here’s what to expect when you’re expecting (to part ways):

Fees and filing

The average cost of divorce can vary not only according to situation but from state to state. The costs can depend on each state’s filing fees, hourly attorney fees, laws dictating residency requirements and waiting periods.

The average contested divorce (where the couple does not agree on terms) can cost between $15,000 to $20,000, according to GoBankingRates. California is the priciest state to get a divorce. Wyoming is the cheapest.

Not every divorce requires a pricy attorney. When Kansas-based personal finance coach Kayla Sloan got divorced at age 20, she said it only cost her the $200 filing fee.

“I represented myself because my ex and I had no real property to speak of, since we were so young,” she said.

However, if you have significant assets and/or children, you’ll likely need a lawyer to determine the final arrangement. That’s when the costs can escalate. The more there is to sort through, the more you’ll more likely the costs will escalate.

Going from double to single

A divorce can be a financial shock to the system, especially when you’re used to splitting expenses with a partner.

After her divorce, Sloan said she took over the entire lease. That left her with just a couple hundred dollars after paying her monthly rent.

“Maybe I should have moved in with roommates to save money,” she said. “But I wasn’t emotionally ready to move all my stuff and start living with new roommates so soon after the divorce.”

Moving, even if you have a friend come help you pack and drive the van to you new place, can come with unexpected expenses too. It’s important to factor in the cost of your security deposit and replacing any household items and furniture you lost in the divorce.

One thing that newly divorced people may not count on is having to pay more for health insurance. A shared insurance plan between spouses will almost always cost significantly more than for a single person, even with markedly reduced coverage.

If you had insurance through your spouse’s job, you may qualify for COBRA coverage — although be aware that it only lasts 18 months.

Looking ahead

After a divorce, you’ve got a big task ahead of you: Rebuilding your heart and your finances.

“It took me five years to get out of all of the debt from the divorce, but I still have not rebuilt all of the assets that I had prior to our marriage,” said Shanah Bell, a Raleigh, NC-based nutritionist  “I am now 7-and-a-half years out, and am only now just getting close to getting my assets fully rebuilt.”

One of the first steps to take is an inventory of your net worth, which will include your assets and liabilities. If your net worth is lower than you feel comfortable with, you may have to consider some big lifestyle changes. This may include selling your house or leasing a less expensive car.

Then, look at your current spending and compare it to your income or the money that actually coming your way versus how it used to be. If you’re now spending more than you’re bringing in, you’re going to end up relying on credit to make up the difference.

Most importantly, don’t t use your new financial situation as an excuse to get into debt–it could send you into a financial spiral that takes years to climb out of.

Read more: What’s Your Money Personality? Understanding Your Financial Self