IndexOutOfBounds exception fixed