improved waitConnected algorithm and set default wait time to wait forever