Fixed nullpointer and adjusted host selection for edge case