Added small fix for reconnect code not working reliably with TLS connections see #177

So based on testing @theojulienne found an issue with the reconnect code not being triggered when TLS connection failed.

The issue relates to TLS connection not triggering a `close` event on disconnect, to work around this when we detect any TLS error on the connection we end it. This ensures the standard lifecycle of the socket is respected while also triggering `close`.

Also just a couple of code tidy / corrections in the same block.

Cheers