Added small fix for reconnect code not working reliably with TLS connections.