Added auto reconnect functionality.