Ssh waitFor() fix

This is the new version of the fix, based on our discussion and latest commits.
It is proven to work for me.