optimize repetition loop
* fixed a bug that would allow going out of bounds of the array.
* do not loop past the last irreversible move.