Startup failure statistics vary widely, but even the rosiest numbers show more than 50 percent failing within five years. Startup founders often have obligations to many stakeholders, including family, employees, investors, and perhaps customers. So when they are forced to face the reality of their business’s failure, they have a responsibility to these groups to do everything in their power to optimize the process of exiting. This starts with understanding the various paths available to you before you have $0 cash in the bank. By that point, many potential exit opportunities will be off the table.

It all starts with communication. It is critically important to communicate regularly and consistently with your stakeholders from the day you launch the company. Communicating honestly and transparently about the good, the bad and the ugly will (a) encourage an environment of collaboration, wherein your stakeholders will work with you to overcome challenges, and (b) help you to avoid surprising your stakeholders if you have to shutter the company.

When you and your cofounders make the decision to exit, I suggest you enlist the help of your investors and advisors. Here are some potential avenues to consider:

1. Compile a list of all of your competitors and prioritize them in order of which ones are most likely to have an interest in buying the company. Then start contacting them. Of course, it’s always better when a potential acquirer contacts you, but you have to face reality. It’s all about optimizing the exit, so speak to as many potential acquirers as possible. Depending on the state of your company, such an acquisition may be considered an acquihire, but that’s okay. Even if you end up with very little or no cash up front, an acquihire can provide important benefits including (a) a payout over time, (b) jobs for you and your cofounders, and (c) jobs for your employees.

2. Compile a list of key customers and suppliers that may be interested in acquiring the company. If a customer or supplier is heavily dependent on your company, they may be interested in buying it. You have to be careful here, because you don’t want to scare customers or suppliers away, especially as you are exploring options to sell the company.  But you can tell them you are considering various alternatives and want to explore whether they may have an interest given the close relationship you share.

3. Assuming you are unable to sell the company as a whole to a competitor, customer or supplier, think about selling certain assets instead. For instance, if a competitor is only interested in the technology you have developed, including, perhaps any patents, you can sell them your intellectual property. There are companies that do nothing but buy patents and you can check with them too.  Also, Google has a program that buys patents.  But your technology doesn’t have to be patented to have significant value.

4. Another asset you should explore selling is your customer accounts. Sometimes your competitors or suppliers may only want to purchase your customer accounts without purchasing your company as a whole. You can and should help transition your customers to the acquirer in the case of a sale. There are also certain industries in which your supplier relationships may be proprietary and may have a value to certain competitors.

5. Some businesses generate a lot of meaningful data. This type of data could be quite valuable to industry and/or financial analysts, market research companies, competitors or others. For example, a company in the travel business, like AllTheRooms.com, has a lot of information about travel trends, which type of accommodation is most popular with each demographic group in every geographic region, detailed pricing information for every hotel and Airbnb, average reservation duration, etc. Another travel company, like Expedia.com, would pay a lot of money for that. Other potential buyers include hotel chains, travel industry analysts, market research companies like Forrester, and perhaps even municipal tourism departments.

6. Sell your inventory, even if that means offering steep discounts.

7. In addition to transitioning your customers to a new company, you have a moral obligation to try to place your employees with other companies. So even if you are unable to sell the company, speak with other companies in the industry, and in related industries, about hiring your employees.

Winding down a startup is never fun and not the outcome any entrepreneur wants or expects. But more often than not, it’s a necessary evil. So you want to do it right, both for your own benefit and for your stakeholders. Remember to consistently communicate with your stakeholders, solicit their assistance and advice, and don’t wait until it’s too late to think strategically about optimizing the value from the various assets you have built.

Phil Nadel is cofounder and Managing Director of Barbara Corcoran Venture Partners, an AngelList syndicate.