Correcting the ArrayOutOfBoundsException