Fix small ssh bugs and improve code