Fix replace bad hosts logic