Fix for segfault

When erasing elements in the vector, the iterator is reset to the
wrong element.