anchor.diff:       %% Assigned -> Begun
        NewAssigned = etorrent_pieceset:delete(Piece, Assigned),
        NewBegun = etorrent_pieceset:insert(Piece, Begun),
  -     NewPrioBegun = update_priority(TorrentID, PrioBegun, NewBegun),
    
        NewState = State#state{
            pieces_begun=NewBegun,
            pieces_assigned=NewAssigned,
  -         chunks_assigned=NewAssignedChunks,
  -         prio_begun=NewPrioBegun},
  +         chunks_assigned=NewAssignedChunks},
       {noreply, NewState};
   
   
   handle_info({scarcity, Ref, Tag, Piecelist}, State) ->
  -    #state{prio_begun=Begun, prio_unassigned=Unass} = State,
  +    #state{piece_priority=PiecePriority} = State,
       %% Verify that the tag is valid before verifying the reference
  -    #pieceprio{tag=Beguntag, ref=Begunref} = Begun,
  -    #pieceprio{tag=Unasstag, ref=Unassref} = Unass,
  -    case Tag of
  -        Beguntag -> ok;
  -        Unasstag -> ok
  -    end,
  -    %% Verify that the reference belongs to an active subscription
  +    #pieceprio{ref=PrioRef} = PiecePriority,
  +    %% Verify that the reference belongs to the active subscription
  +    %% If not, drop the update and hope that it was a stray one.
       NewState = case Ref of
  -        Begunref ->
  -            NewBegun = Begun#pieceprio{pieces=Piecelist},
  -            State#state{prio_begun=NewBegun};
  -        Unassref ->
  -            NewUnass = Unass#pieceprio{pieces=Piecelist},
  -            State#state{prio_unassigned=NewUnass};
  +        PrioRef ->
  +            NewPriority = PiecePriority#pieceprio{pieces=Piecelist},
  +            State#state{piece_priority=NewPriority};
           _ ->
               State
       end,
  
positive.code:                     NewUnassigned = etorrent_pieceset:delete(Index, Unassigned),
                      NewBegun = etorrent_pieceset:insert(Index, Begun),
                      NewAssigned = Assigned,
                      UnassignedUpdated = true,
                      BegunUpdated = true;
                  {unassigned, assigned} ->
                      NewUnassigned = etorrent_pieceset:delete(Index, Unassigned),
                      NewBegun = Begun,
                      NewAssigned = etorrent_pieceset:insert(Index, Assigned),
                      UnassignedUpdated = true,
                      BegunUpdated = false;
                  {begun, begun} ->
                      NewUnassigned = Unassigned,
                      NewBegun = Begun,
                      NewAssigned = Assigned,
                      UnassignedUpdated = false,
                      BegunUpdated = false;
                  {begun, assigned} ->
                      NewUnassigned = Unassigned,
                      NewBegun = etorrent_pieceset:delete(Index, Begun),
                      NewAssigned = etorrent_pieceset:insert(Index, Assigned),
                      UnassignedUpdated = false,
                      BegunUpdated = true
              end,
  
              %% Only update the piece priority lists if the piece set that
              %% they track was updated in this piece state transition.
              NewPrioUnassigned = case UnassignedUpdated of
                  false -> PrioUnassigned;
                  true  -> update_priority(TorrentID, PrioUnassigned, NewUnassigned)
              end,
              NewPrioBegun = case BegunUpdated of
                  false -> PrioBegun;
                  true  -> update_priority(TorrentID, PrioBegun, NewBegun)
              end,
  
              %% The piece is in the assigned state if this was the last chunk
              NewAssigned = case etorrent_chunkset:size(NewChunkset) of
                  0 -> etorrent_pieceset:insert(Index, Assigned);
                  _ -> Assigned
              end,
              NewState = State#state{
                  pieces_unassigned=NewUnassigned,
                  pieces_begun=NewBegun,
                  pieces_assigned=NewAssigned,
                  chunks_assigned=NewAssignedChunks,
                  prio_unassigned=NewPrioUnassigned,
                  prio_begun=NewPrioBegun},
              {reply, {ok, Chunks}, NewState}
      end;
  
  
negative.code:         %% Initially, the sets of assigned and stored chunks are equal
          chunks_assigned=ChunkSets,
          chunks_stored=ChunkSets,
          piece_priority=PiecePriority,
          pending=Pending},
      {ok, InitState}.
  
  