improved ssl logic