Added support for DNS and cleaned up the code a bit