Fix invalidated iterator usage.