Introduce the xr + n < p condition in the step where it is needed, namely right before switching from integer equality to equality modulo p, and explain why it is required there. Write congruences as a == b (mod m), because a mod p == b reads as if mod p were an operator applied to the left-hand side only.
Also reword the comment at the p - n check: the check is needed for correctness, not merely an optimization.
Made these improvements when trying to understand the background of #1948.