TLS fixes.

Various fixes for issues regarding TLS.