Refactor waiting for SSH

Remove duplicate code
perltidy
Fix case
Fix typo