anchor.diff:  -record(state, {
       torrent_id      :: pos_integer(),
       chunk_size      :: pos_integer(),
  +    %% Piece state sets
       pieces_valid    :: pieceset(),
       pieces_begun    :: pieceset(),
       pieces_assigned :: pieceset(),
       pieces_stored   :: pieceset(),
  -    piece_chunks    :: array(),
  +    %% Chunk sets for pieces
  +    chunks_assigned :: array(),
  +    chunks_stored   :: array(),
  +    %% Chunks assigned to peers
       peer_monitors   :: monitorset()}).
   
   %% # Open requests
  
positive.code: 
      NumPieces = length(PieceSizes),
      PiecesValid   = etorrent_pieceset:from_list(FetchedPieces, NumPieces),
      PiecesChunked = etorrent_pieceset:new(NumPieces),
  
      %% Initialize a full chunkset for all pieces that are left to download
      %% but don't mark them as chunked before a chunk has been deleted from
      %% any of the chunksets.
      AllIndexes = lists:seq(0, NumPieces - 1),
      AllPieces = etorrent_pieceset:from_list(AllIndexes, NumPieces),
      PiecesInvalid = etorrent_pieceset:difference(AllPieces, PiecesValid),
      ChunkList = [begin
          Size = orddict:fetch(N, PieceSizes),
          Set  = etorrent_chunkset:new(Size, ChunkSize),
          {N, Set}
      end || N <- etorrent_pieceset:to_list(PiecesInvalid)],
  
      %% Initialize an empty chunkset for all pieces that are valid.
      CompletedList = [begin
          Size = orddict:fetch(N, PieceSizes),
          Set  = etorrent_chunkset:from_list(Size, ChunkSize, []),
          {N, Set}
      end || N <- etorrent_pieceset:to_list(PiecesValid)],
  
      AllChunksets = lists:sort(CompletedList ++ ChunkList),
      PieceChunks  = array:from_orddict(AllChunksets),
  
      InitState = #state{
          torrent_id=TorrentID,
          chunk_size=ChunkSize,
          pieces_valid=PiecesValid,
          pieces_begun=PiecesChunked,
          piece_chunks=PieceChunks,
          peer_monitors=etorrent_monitorset:new()},
      {ok, InitState}.
  
  
negative.code: 
  handle_call({request_chunks, PeerPid, Peerset, Numchunks}, _, State) ->
      #state{
          pieces_valid=Valid,
          pieces_begun=Begun,
          pieces_assigned=Assigned,
          pieces_stored=Stored,
          chunks_assigned=AssignedChunks,
          peer_monitors=Peers} = State,
  
      %% Consider pieces that has an empty chunkset 
      
      %% If this peer has no pieces that we are already downloading, begin
      %% downloading a new piece if this peer has any interesting pieces.
      Optimal = etorrent_pieceset:intersection(Peerset,
                etorrent_pieceset:difference(Begun, Assigned)),
      SubOptimal = etorrent_pieceset:difference(Peerset, Assigned),
      NumOptimal = etorrent_pieceset:size(Optimal),
      NumSubOptimal = etorrent_pieceset:size(SubOptimal),
  
      ?debugVal({NumOptimal, NumSubOptimal}),
      PieceIndex = case {NumOptimal, NumSubOptimal} of
  