Fix a use of an invalidated iterator in the case where there are multiple