Fix iterator usage so msvc doesn't crash in debug mode.