Fix out of bounds exception

Fixed the IndexOutOfBounds exception