Refactor dns management