index out of bounds fix