Added ability to automatically reconnect on connection failure.