Refactored detachTrackedEntities