When combining several $\tan^{-1}$ terms, add or subtract them two at a time using the standard formulas. Before accepting a sum, check whether the product of the two arguments exceeds 1 — if it does, you must add $\pi$ to stay in the correct range. Also watch for values that are reciprocals of each other, since their sum simplifies immediately to $\pi/2$.