Fixed a bug in the reconnect mechanism.