Added SSH support, including a lot of code reorganisation