Improvements to ssl handling