array index out of bounds fix