uses exceptions and added test for bad hosts