fixed connection/disconnection bug