first refactor of the ssh build_tunnel function