refactored ssh remote handling