_wait_for_ssh refactored