anchor.diff:      Rows = ets:select(?TAB, [{MatchHead, [], ['$_']}]),
       lists:foreach(F, Rows),
       ok.
  +
  +-ifdef(TEST).
  +-include_lib("eunit/include/eunit.hrl").
  +-define(chunk_server, ?MODULE).
  +
  +chunk_server_registry_test() ->
  +    ?assertEqual(true, ?chunk_server:register_chunk_server(1)),
  +    ?assertEqual(self(), ?chunk_server:lookup_chunk_server(1)).
  +
  +
  
positive.code: pick_chunks(endgame, {Id, PieceSet, N}) ->
      Remaining = find_remaining_chunks(Id, PieceSet),
      Shuffled = etorrent_utils:list_shuffle(Remaining),
      Grouped = gather(
  		lists:sort(
  		  lists:sublist(Shuffled, N))),
      {endgame, etorrent_utils:list_shuffle(Grouped)}.
  
  %% Gather like pieces in the endgame
  gather([]) -> [];
  gather([{PN, Off, Sz} | R]) ->
      gather(PN, [{Off, Sz}], R).
  
  gather(PN, Item, []) ->
      [{PN, lists:sort(Item)}];
  gather(PN, Items, [{PN, Off, Sz} | Next]) ->
      gather(PN, [{Off, Sz} | Items], Next);
  gather(PN, Items, [{PN2, Off, Sz} | Next]) ->
      [{PN, lists:sort(Items)} | gather(PN2, [{Off, Sz}], Next)].
  
  
  -spec pick_chunks_endgame(integer(), gb_set(), integer(), X) -> X | {endgame, [#chunk{}]}.
  pick_chunks_endgame(Id, Set, Remaining, Ret) ->
  
negative.code: 
  %% @doc Return some chunks for downloading.
  %% @end
  -type chunk_lst1() :: [{integer(), integer(), integer(), [operation()]}].
  -type chunk_lst2() :: [{integer(), [#chunk{}]}].
  -spec pick_chunks(torrent_id(), unknown | pieceset(), pos_integer()) ->
      none_eligible | not_interested | {ok | endgame, chunk_lst1() | chunk_lst2()}.
  pick_chunks(_, unknown, _) ->
      none_eligible;
  pick_chunks(TorrentID, Peerset, Numchunks) ->
      Chunkserver = lookup_chunk_server(TorrentID),
      gen_server:call(Chunkserver, {pick_chunks, Peerset, Numchunks}).
  
  
  %% ----------------------------------------------------------------------
  %% @doc Choose up to Max chunks from Selected.
  %%  Will return {ok, {Index, Chunks}, size(Chunks)}.
  %% @end
  -spec select_chunks_by_piecenum({pos_integer(), pos_integer()}, pos_integer()) ->
  