anchor.diff:                                                          live_subs = Subs,
                                                           queue = Q,
                                                           retained = Ret}) ->
  -    {Pid,Packets,Sub} = mqtt_sub_state:new(Pid,CSeq,QoS,WSize,Q,Ret),
  +    {Packets,Sub} = mqtt_sub_state:new(Pid,CSeq,QoS,WSize,Q,Ret),
       send_packets_to_client(Pid,Filter,Packets),
  -    S#state{live_subs = dict:store(ClientId,Sub,Subs),
  +    S#state{live_subs = dict:store(ClientId,{Pid,Sub},Subs),
               queue = shared_queue:add(ClientId,Q)}.
   
   %%
   %% Only update existing properties - this is not a new subscription
   %%
  -resubscribe(ClientId,QoS,Sub,S = #state{filter = Filter,
  -                                        retained = Ret,
  -                                        queue = Q,
  -                                        live_subs = Subs}) ->
  -    {Pid,Packets,Sub1} = mqtt_sub_state:resubscribe(QoS,Q,Ret,Sub),
  +resubscribe(ClientId,QoS,Pid,Sub,S = #state{filter = Filter,
  +                                            retained = Ret,
  +                                            queue = Q,
  +                                            live_subs = Subs}) ->
  +    {Packets,Sub1} = mqtt_sub_state:resubscribe(QoS,Q,Ret,Sub),
       send_packets_to_client(Pid,Filter,Packets),
  -    S#state{live_subs = dict:store(ClientId,Sub1,Subs)}.
  +    S#state{live_subs = dict:store(ClientId,{Pid,Sub1},Subs)}.
   
   %% @doc
   %% We know that a client is subscribed to a queue, we just don't know the index (Seq number)
  
positive.code:     ShouldResume =
          case dict:find(ClientId,Subs) of
              error -> true;
              {ok,Sub} -> not mqtt_sub_state:is_old(CSeq,Sub)
          end,
      case ShouldResume of
          true ->
              {Pid,Packets,Sub1} = mqtt_sub_state:new(Pid,CSeq,QoS,ResumeFrom,WSize,SQ,Ret),
              send_packets_to_client(Pid,Filter,Packets),
              S#state{live_subs = dict:store(ClientId,Sub1,Subs)};
          _ -> S
      end.
  
  
negative.code:                                       live_subs = Subs,
                                        queue = SQ}) ->
      case dict:find(ClientId,Subs) of
          {ok,{Pid,Sub}} ->
              {Packets,Sub1} = mqtt_sub_state:take(WSize,SQ,Sub),
              S1 = S#state{live_subs = dict:store(ClientId,{Pid,Sub1},Subs)},
              send_packets_to_client(Pid,Filter,Packets),
              S1;
          error -> S
      end.
  
  