move SSL check to a seprate function