fixed connection state bug and refcnt bugs