Fix iterator bounds checking