Refactor ssh and add terminfo module