anchor.diff:          [undefined|_] ->
               error_logger:error_msg("~p:promote_replicas(~p, ~p, ~p, ~p): No master~n", [?MODULE, Bucket, V, RemapNodes, Chain]),
               NewChainExtended;
  -        [_|_] ->
  +        [NewMaster|_] ->
  +            error_logger:info_msg("~p:promote_replicas(~p, ~p, ~p, ~p): Setting node ~p active for vbucket ~p~n",
  +                                  [?MODULE, Bucket, V, RemapNodes, Chain, NewMaster, V]),
  +            ns_memcached:set_vbucket_state(NewMaster, V, active),
               NewChainExtended
       end.
   
   histograms(Map, Servers) ->
  -    Histograms = [lists:keydelete(undefined, 1, misc:uniqc(lists:sort(L))) || L <- misc:rotate(Map)],
  +    Histograms = [lists:keydelete(
  +                    undefined, 1,
  +                    misc:uniqc(
  +                      lists:sort(
  +                        [N || N<-L,
  +                              lists:member(N, Servers)]))) ||
  +                     L <- misc:rotate(Map)],
       lists:map(fun (H) ->
  -                      Missing = [{N, 0} || N <- Servers, not lists:keymember(N, 1, H)],
  +                      Missing = [{N, 0} || N <- Servers,
  +                                           not lists:keymember(N, 1, H)],
                         Missing ++ H
                 end, Histograms).
   
  
positive.code: %% Internal functions
  assign(Histogram, AvoidNodes) ->
      Histogram1 = lists:keysort(2, Histogram),
      case lists:splitwith(fun ({N, _}) -> lists:member(N, AvoidNodes) end, Histogram1) of
          {Head, [{Node, N}|Rest]} ->
              {Node, Head ++ [{Node, N+1}|Rest]};
          {_, []} ->
              {undefined, Histogram1}
      end.
  
  do_rebalance(Bucket, KeepNodes, EjectNodes, Map) ->
  
negative.code:         [] -> true;
          Counts -> lists:max(Counts) - lists:min(Counts) > 2
      end.
  
  update_progress(Histograms) ->
      Groups = misc:keygroup(1, lists:keysort(1, lists:append(Histograms))),
      Counts = [{Node, Count}|| {Node, H} <- Groups,
                                Count <- lists:foldl(fun ((X), Y) -> X + Y end, H)].
  