#9 reorganizing logic to support ssl certificates