added support for automatically reconnecting after a disconnect