Fix iterator being out of bounds