Perhaps the company is doing poorly financially or the atmosphere at the office no longer feels welcoming. If you see any of these issues, you can’t afford to stick your head in the sand and hope it will pass.

What To Do if You Think You’re Going To Be Fired

While certain aspects of your relationship with your employer are beyond your control—for example, if the company is failing, no amount of effort on your part will alter that—there are some things you can do to try to save your job.

1. Talk to Your Boss

If your boss knows you’re on your way out—but can’t tell you yet—chances are that they’re doing their level best to avoid conversation. Your goal: open the lines of communication, without looking desperate. This is easier said than done. If there’s a layoff coming, or you’re about to be fired for another reason, your manager has every incentive not to talk to you. For one thing, they will want to avoid giving anything away; for another, unless they’re a monster, your boss probably feels pretty bad about the situation right now, regardless of how you’ve been getting along. In other words, talking about your day-to-day work is good, while insisting on getting the lowdown on your future with the company is very, very bad. If your boss will talk to you, and you feel a certain level of comfort in the conversation, it may be safe to ask how things are going. Let them know that you’re always interested in hearing constructive criticism of your performance. This is particularly useful if your relationship with your employer is only just starting to sour. Make sure you’re willing to practice what you preach, take seriously any feedback you receive, and take steps to show that you’re improving.  If your boss won’t talk to you at all, you’ll at least know that things are beyond salvaging, and will be able to make other plans.

2. Join a New Team

Sometimes, managers and reports just don’t connect, through no fault of anyone involved. If you feel like you and your boss no longer see eye to eye, it might be time to look for openings on other teams in the company. You can get a fresh start without rolling over your 401(k) and starting over somewhere else. This is also a good approach if the issue is that your department is on the chopping block, and you’re facing a layoff. Look for teams whose budgets and headcount seem to increase every quarter. That’s the safest place to weather any coming storms.

3. Look for Essential Projects

Quick: what does your company do? If it’s like most organizations, it has a core product or products that are the basis for its reputation and business. If you’re looking for a new home at the company, getting closer to these projects will help you stay off the layoff list.

4. Do Some Soul-Searching

Many companies conduct annual performance reviews, but a year can be a long time in your tenure at an organization. Ask yourself whether you’re still meeting your goals and making progress on “needs-to-improve” areas. If you come up short in your own assessment, make a plan to remedy the situation. Then, make sure that your boss knows what you’re working on. On the other hand, if you feel like you’re doing what you should be doing, think about whether you’re communicating that to the right people. Politics is perception, even on a small scale. It’s not just what you do, but what you’re seen doing. If you’re someone who shies away from tooting your own horn, remember that no one knows how hard you’re working unless you communicate that to them. It’s not bragging if it’s true, and if you don’t tell your boss what you’re doing, someone else can claim the credit.

5. Ask To Be Laid Off Instead

If you’ve tried to fix things with your manager, improve your performance, and ally yourself with another department, and can’t make it work, you have one last card to play: ask to be laid off. You’re more likely to be eligible for unemployment if your termination is considered a layoff rather than being fired for cause or quitting. From the employer’s perspective, a layoff might be preferable, too, even if it means paying out unemployment because they can require you to sign a document stating that you won’t pursue legal action for wrongful termination. This is a cost savings for them, as well as a better situation financially and professionally for you. In any case, it can’t hurt to ask.

6. Know When It’s Time To Go

Finally, it’s important to note that sometimes, your number is just up. If you get the sense that you’re about to lose your job, whether through a layoff or by being fired, now is the time to update your resume, make coffee dates with former colleagues, and connect with old bosses on LinkedIn. Whatever you do, keep it professional—and keep your chin up. Some of the most successful people in the world have been fired from jobs and gone on to great things. One reversal isn’t necessarily a judgment on your abilities today or in the long run. Take what you’ve learned and move on to bigger and better things.