Refactor out the safe cleanup.