[AI-409] Custom domains: cleanup, refactoring