No one likes doing it, but sometimes bosses have no choice but to let go of employees. But before doing so, make sure that you’re not setting yourself up for a slew of more trouble — legal trouble.

Art Lambert, partner at the Dallas law office of Fisher & Phillips, outlines how to terminate an employee without getting sued.

Know the laws of your state: All states but Montana use the at-will doctrine, which allows managers to terminate employment for any reason. However, a handful of states have implemented an exemption to the doctrine that requires employers to act in good faith and fair dealing when terminating workers. Such states, including California, require employers to have a just cause for termination. On the other hand, Texas and the majority of states allow employers to fire workers for any legal, non-discriminatory reason — even if it’s just for their inability to get along with co-workers.

Be consistent: If employees are in a protected class (race, color, gender, religion, age, disability, etc…), they could bring a claim for discrimination under state or federal law based on the termination. To defend against these claims, demonstrate that there was a legitimate, non-discriminatory reason for the termination. To avoid a lawsuit, an employer should be able to show a consistent pattern of treatment among all employees who have had difficulty getting along with their co-workers.

Write everything down: The best proof of consistency is documentation. It’s important to write about the actual behavior problems and any meetings where those issues were called to the employee’s attention. This ensures that everyone will be on the same page if the termination is later called into question. It also acts as proof of the reasons for the termination.

Offer a severance: Offer pay to terminated employees in exchange for their release of any claims they may have against your business. A messy termination can be cleaned up even if the employer has done nothing wrong.

Hand over that final paycheck — promptly: Many states have specific laws as to when employees who are involuntarily terminated must be handed their final paycheck. And it’s worth noting that without specific written authorization, an employer may not deduct anything from that check.