anchor.diff:  chains1(_, 0, _) ->
       [];
   chains1(Counts, NumVBuckets, NumCopies) ->
  -    {Chain, Counts1} = chains2(Counts, undefined, 1, NumCopies),
  +    {Chain, Counts1} = chains2(Counts, undefined, 1, NumCopies, []),
       [Chain | chains1(Counts1, NumVBuckets - 1, NumCopies)].
   
   
  -chains2(Counts, PrevNode, Turn, Turns) when Turn =< Turns ->
  +chains2(Counts, PrevNode, Turn, Turns, ChainReversed) when Turn =< Turns ->
       Key = {PrevNode, Turn},
       %% The first node in the list for this master and turn is the node
       %% with the lowest count. We keep the list sorted by count.
  -    {Total, {Count, Node}, Rest} =
  -        best_node(dict:fetch({PrevNode, Turn}, Counts), Turn, Counts),
  -    Counts1 = dict:store({total, Node, Turn}, Total+1, Counts),
  -    Counts2 = dict:store(Key, sorted_insert({Count+1, Node}, Rest), Counts1),
  -    {Chain, Counts3} = chains2(Counts2, Node, Turn+1, Turns),
  -    {[Node|Chain], Counts3};
  -chains2(Counts, _, _, _)  ->
  -    {[], Counts}.
  +    NodeCounts = dict:fetch({PrevNode, Turn}, Counts),
  +    {Count, Node} =
  +        best_node(NodeCounts, Turn, Counts, ChainReversed),
  +    Counts1 = dict:update_counter({total, Node, Turn}, 1, Counts),
  +    Counts2 = dict:store(Key, lists:keyreplace(Node, 2, NodeCounts,
  +                                               {Count+1, Node}), Counts1),
  +    chains2(Counts2, Node, Turn+1, Turns, [Node|ChainReversed]);
  +chains2(Counts, _, _, _, ChainReversed)  ->
  +    {lists:reverse(ChainReversed), Counts}.
   
   
   %% @private
  
positive.code:                                       Acc andalso SlaveCount == NumSlaves
                                            andalso Min /= really_big
                                            andalso Max > 0
                                            andalso Max - Min =< 1
                                end, true, SlaveCounts)
                      end
              end
  
negative.code: %% beginning of a sorted list consisting of counts of vbuckets *at
  %% this turn for this master* followed by the node name. Also returns
  %% the remainder of the list to make it easy to update the count.
  best_node(NodeCounts, Turn, Counts, Blacklist) ->
      NodeCounts1 = [{Count, dict:fetch({total, Node, Turn}, Counts), Node}
                     || {Count, Node} <- NodeCounts,
                        not lists:member(Node, Blacklist)],
      {Count, _, Node} = lists:min(NodeCounts1),
      {Count, Node}.
  
  
  %% @private
  