IndexArrayOutOfBounds exception fix