Fix iterator-related things

After using erase() on an iterator, the iterator is invalided. It should either receive a new value from the erase() method or not be used anymore.

The other issue is minor, but generates warnings with cppcheck: using pre-increments for iterators is recommended.