anchor.diff:          true  ->
               #state{ rpcs = RPC0 } = S0,
               {Id, Reply} = make_reply(Frame),
  -            From = gb_trees:get(Id, RPC0),
  +            {Ref, From} = gb_trees:get(Id, RPC0),
               RPC1 = gb_trees:delete(Id, RPC0),
  -            From ! {Id, Reply},
  +            From ! {Ref, Reply},
               {next_state, opened, S0#state{ rpcs = RPC1 }};
           false ->
               %% TODO deal with QoS
  
positive.code:     ok = gen_tcp:send(S, mqtt_framing:serialise(Frame)),
      ok.
  
  %% Record the fact of an RPC and send the frame with the correct id.
  rpc(S0, Req, From) ->
      #state{ id_counter = Id,
              rpcs = RPC0 } = S0,
      RPC1 = gb_trees:insert(Id, From, RPC0),
      write(S0, with_id(Id, Req)),
      S0#state{ id_counter = Id + 1, rpcs = RPC1 }.
  
  
negative.code:           receiver_monitor = undefined
           }).
  
  -type(error() :: {'error', term()}).
  
  -type(connection() :: pid()).
  
  start_link() ->
      gen_fsm:start_link(?MODULE, [], []).
  
  -spec(connect(connection(), address(), client_id()) -> ok | error()).
  connect(Conn, Address, ClientId) ->
      connect(Conn, Address, ClientId, []).
  
  -spec(connect(connection(),
                address(),
                client_id(),
                [connect_option() | {'receiver', pid()}]) -> ok | error()).
  connect(Conn, Address, ClientId, ConnectOpts0) ->
      Connect = #connect{ client_id = iolist_to_binary([ClientId]) },
      Receiver = proplists:get_value(receiver, ConnectOpts0, self()),
  