Fix another crash related to invalid iterators/indices