Moved host detection code to DRY up the code some more