Refactor clean_domains