protected static function domainFixup($domain)
    {
        if (strlen($domain) > 0) {
            $dl = strlen($domain) - 1;
            // remove trailing '.'
            if ($domain{$dl} === '.') {
                $domain = substr($domain, 0, $dl);
            }
            // remove leading '*'
            if (substr($domain, 0, 2) === '*.') {
                $domain = substr($domain, 1);
            }
        }

        return $domain;
    }