fix out of bounds index