Copying remainders outside the while saves on bounds checking inside the while for a nice speedup