improve code, add reconnect mechanism.