Fix a coredump found in regressions. We were using an iterator after an erase.
Fix a small error with changing from the iterator to [] accessing.