TLS connection handling fixes