prevent erasing the end iterator if the removed item is not selected.