Fix bug in erase (erasing invalid iterator)