split out some hairy code to dns_logic