Fixed array index out of bounds at level end