Refactor ssl code