Fix error with ssh, big refactor