implemented automatic reconnect