Refactoring and optimization in Entity::removeEntityFromNodes