Added check if host is reachable before trying to connect