Fix bugs in findHost function