Added some error checking for TLS connections.