Refactor to switch to SSL before negotiating protocol