restructured a bit for clarity
fixed to for client DNS name support
added working IPv6 support