Fixes ssh loop error for pseudo tty terminal's and refactors utils