flipping array index out of range