made dns naming more robust

Fixes some issues with generated domain names. Added tests.