Refactor custom domain controller logic