Added proper function exit for invalid hostnames