Corrected bug which meant the final residue was written n times, where n in the number of footer lines