If you’re a small business owner, retirement planning can be especially complicated. For starters, you have to fund your own retirement. With no employer-sponsored plan, it’s up to you to manage your own IRAs, solo 401(k)s and the like.

You’ll also have to decide what should happen to your business after you retire. For most owners, this is no easy task. After you’ve spent decades building up a business, it can be difficult to sell, from both a practical and an emotional perspective—especially if you’re worried about protecting your company and taking care of your customers and employees.

Start Planning Early

If you think you might want to sell, it pays to start planning early. In general, experts recommend you take at least two years to get your business market-ready and your paperwork in order—including two to three years of tax returns that show how profitable your business can be. Keep in mind, if you have a history of running everything through the business as a tax write-off, your company will appear less profitable and potential buyers will be more likely to undervalue your business.

Shift Gears

Your business may be profitable, but if it’s too dependent on you—or on a single customer—potential buyers might look elsewhere. If that’s the case and you think you’ll eventually want to sell, you will need to spend some time revamping your business model so that it could thrive without you or that key customer (it can be helpful here to work with an experienced small business consultant). This includes training employees to take over some of your management roles. In general, your business should be able to operate (i.e., continue to sell goods and/or services, and fulfill those orders) even if you’re on vacation—and no single customer should represent more than 5 percent of your revenue.

Time It Right

If you’re having a banner year but retirement is still a few years off, it still might make sense to go ahead and sell now, if that’s what you’re planning to do. Many people wait until their business has peaked and started to decline to sell. That’s understandable, since it’s hard to sell when you’re making good money. The problem with waiting, however, is that potential buyers may see your company is no longer as profitable—for whatever reason—and will value your company accordingly.

Conversely, if market conditions aren’t right, it might pay to hold on for a few more years until your industry rebounds. Home improvement businesses are a good example. If you sold your construction business in 2006—before the Great Recession—you may have done well. A few years later, however, the industry was so depressed that it would have been difficult to get an appropriate return on your investment. In such cases, it’s a good idea to wait until market conditions improve before selling, if that’s an option.

If You Do Sell

Most business owners do plan on selling when it’s time to retire so they can pursue something else, enjoy a little free time and, of course, use the sale proceeds to fund their retirement. In fact, 78 percent of small business owners plan to sell their company to fund 60-100 percent of their retirement, according to CNBC and the Financial Planning Association.

If you decide to sell, you’ll need to figure out your company’s value. Start by looking at your assets and liabilities, and your profits in recent years. Next, do a bit of detective work to find out what similar businesses are selling for, paying close attention to the multiple they are selling for based on their earnings. Again, working with a qualified consultant or business broker can be immensely helpful.

It’s also important to have a succession plan in place that will be used to introduce buyers to your business process, employees and customers. A thorough plan will help smooth the transition and improve the odds that your company will continue to thrive with someone else at the helm. And that can help enjoy your retirement even more.