anchor.diff:          torrent_id=TorrentID,
           torrent_pid=TorrentPid,
           chunk_size=ChunkSize,
  +        %% All Valid pieces stay Valid
           pieces_valid=PiecesValid,
  -        %% All valid pieces are also begun, assigned and stored
  -        pieces_begun=PiecesValid,
  -        pieces_assigned=PiecesValid,
  -        pieces_stored=PiecesValid,
  +        %% All Invalid pieces are Unassigned
  +        pieces_unassigned=PiecesInvalid,
  +        %% No pieces have are yet Begun, Assigned or Stored
  +        pieces_begun=PiecesNone,
  +        pieces_assigned=PiecesNone,
  +        pieces_stored=PiecesNone,
           %% Initially, the sets of assigned and stored chunks are equal
           chunks_assigned=ChunkSets,
           chunks_stored=ChunkSets,
  
positive.code:     true = register_chunk_server(TorrentID),
  
      NumPieces = length(PieceSizes),
      PiecesValid   = etorrent_pieceset:from_list(FetchedPieces, NumPieces),
  
      %% Initialize a full chunkset for all pieces that are left to download
      %% but don't mark them as begun before a chunk has been deleted from
  
negative.code:                 gb_trees:insert({Index, Offs}, Len, Acc)
              end, OpenReqs, Chunks),
              NewPeers = etorrent_monitorset:update(PeerPid, NewReqs, Peers),
  
              %% We need to consider four transitions at this point:
              %% Unassigned -> Begun
              %% Unassigned -> Assigned
              %% Begun -> Begun
              %% Begun -> Assigned
              %% The piece may have gone directly from Unassigned to Assigned.
              %% Check if it has been assigned before making any transitions.
              %% TODO - we want an is_empty function in etorrent_chunkset
              Wasassigned = etorrent_chunkset:size(NewChunkset) == 0,
              NewUnassigned = case Targetstate of
                  %% Begun -> Begun
                  begun ->
                      Unassigned;
                  %% Unassigned -> Begun|Assigned
                  unassigned ->
                      etorrent_pieceset:delete(Index, Unassigned)
              end,
  
              NewBegun = case Targetstate of
                  %% Begun -> Assigned
                  begun when Wasassigned ->
                      etorrent_pieceset:delete(Index, Begun);
                  %% Begun -> Begun
                  begun ->
                      Begun;
                  %% Unassigned -> Assigned
                  unassigned when Wasassigned ->
                      Begun;
                  %% Unassigned -> Begun
                  unassigned ->
                      etorrent_pieceset:insert(Index, Begun)
              end,
  
              NewAssigned = case Targetstate of
                  %% Unassigned|Begun -> Assigned
                  _ when Wasassigned ->
                      etorrent_pieceset:insert(Index, Assigned);
                  %% Begun -> Begun
                  begun ->
                      Assigned;
                  %% Unassigned -> Begun
                  unassigned ->
                      Assigned
              end,
              %% TODO - update order watches if Unassigned or Begun changed
              NewState = State#state{
                  pieces_unassigned=NewUnassigned,
                  pieces_begun=NewBegun,
                  pieces_assigned=NewAssigned,
                  chunks_assigned=NewAssignedChunks,
  