changed: improved logic in delete_entity