Delete the entity before removing from the list

Old code was calling dereference on invalid iterator