Fixing a segfault scenario where iter is referenced after it was erased.