Added safe removal of entities