better way to check SSH connection, fix a bug