Fix IndexOutOfBounds bug