Adding better error handling for invalid hostnames