cleaned up pointer gymnastics and unused var n in query function
added support for CNAME