fixed bug where iterator was invalidated by an erase and used