Removing undefined behavior for accessing vector elements with invalid indexes

Behavior is undefined for accessing vector[n] if n >= vector.size()
Updating vector iterator after vector::erase() call, since the vector iterators become invalid