Change it back to my initial fix of subtracting 1 from the x and y loops variables.
The previous change would have broken the normal generation.
Also moved the abort checks to somewhere more sensible.