implemented auto-reconnect