Refactor ssh functions