Add DNS error handling and some modularity