anchor.diff:      end.
   
   
  -reduce_stream_node(_Bt, _Dir, nil, _KeyStart, _KeyEnd, GroupedKey, GroupedKVsAcc,
  +reduce_stream_node(_Bt, _Dir, nil, _KeyStart, _InEndRangeFun, GroupedKey, GroupedKVsAcc,
           GroupedRedsAcc, _KeyGroupFun, _Fun, Acc) ->
       {ok, Acc, GroupedRedsAcc, GroupedKVsAcc, GroupedKey};
  -reduce_stream_node(Bt, Dir, Node, KeyStart, KeyEnd, GroupedKey, GroupedKVsAcc,
  +reduce_stream_node(Bt, Dir, Node, KeyStart, InEndRangeFun, GroupedKey, GroupedKVsAcc,
           GroupedRedsAcc, KeyGroupFun, Fun, Acc) ->
       P = element(1, Node),
       case get_node(Bt, P) of
       {kp_node, NodeList} ->
  -        reduce_stream_kp_node(Bt, Dir, NodeList, KeyStart, KeyEnd, GroupedKey,
  +        NodeList2 = adjust_dir(Dir, NodeList),
  +        reduce_stream_kp_node(Bt, Dir, NodeList2, KeyStart, InEndRangeFun, GroupedKey,
                   GroupedKVsAcc, GroupedRedsAcc, KeyGroupFun, Fun, Acc);
       {kv_node, KVs} ->
  -        reduce_stream_kv_node(Bt, Dir, KVs, KeyStart, KeyEnd, GroupedKey,
  +        KVs2 = adjust_dir(Dir, KVs),
  +        reduce_stream_kv_node(Bt, Dir, KVs2, KeyStart, InEndRangeFun, GroupedKey,
                   GroupedKVsAcc, GroupedRedsAcc, KeyGroupFun, Fun, Acc)
       end.
   
  -reduce_stream_kv_node(Bt, Dir, KVs, KeyStart, KeyEnd,
  +reduce_stream_kv_node(Bt, Dir, KVs, KeyStart, InEndRangeFun,
                           GroupedKey, GroupedKVsAcc, GroupedRedsAcc,
                           KeyGroupFun, Fun, Acc) ->
   
  
positive.code:     undefined ->
          NodeList;
      _ ->
          lists:dropwhile(
              fun({Key,_}) ->
                  less(Bt, Key, KeyStart)
              end, NodeList)
      end,
      NodesInRange =
      case KeyEnd of
      undefined ->
          Nodes;
      _ ->
          {InRange, MaybeInRange} = lists:splitwith(
              fun({Key,_}) ->
                  less(Bt, Key, KeyEnd)
              end, Nodes),
          InRange ++ case MaybeInRange of [] -> []; [FirstMaybe|_] -> [FirstMaybe] end
      end,
      reduce_stream_kp_node2(Bt, Dir, adjust_dir(Dir, NodesInRange), KeyStart, KeyEnd,
          GroupedKey, GroupedKVsAcc, GroupedRedsAcc, KeyGroupFun, Fun, Acc).
  
  
  reduce_stream_kp_node2(Bt, Dir, [{_Key, NodeInfo} | RestNodeList], KeyStart, KeyEnd,
                          undefined, [], [], KeyGroupFun, Fun, Acc) ->
      {ok, Acc2, GroupedRedsAcc2, GroupedKVsAcc2, GroupedKey2} =
              reduce_stream_node(Bt, Dir, NodeInfo, KeyStart, KeyEnd, undefined,
                  [], [], KeyGroupFun, Fun, Acc),
      reduce_stream_kp_node2(Bt, Dir, RestNodeList, KeyStart, KeyEnd, GroupedKey2,
              GroupedKVsAcc2, GroupedRedsAcc2, KeyGroupFun, Fun, Acc2);
  reduce_stream_kp_node2(Bt, Dir, NodeList, KeyStart, KeyEnd,
          GroupedKey, GroupedKVsAcc, GroupedRedsAcc, KeyGroupFun, Fun, Acc) ->
      {Grouped0, Ungrouped0} = lists:splitwith(fun({Key,_}) ->
          KeyGroupFun(GroupedKey, Key) end, NodeList),
  
negative.code:     case UngroupedNodes of
      [{_Key, NodeInfo}|RestNodes] ->
          {ok, Acc2, GroupedRedsAcc2, GroupedKVsAcc2, GroupedKey2} =
              reduce_stream_node(Bt, Dir, NodeInfo, KeyStart, InEndRangeFun, GroupedKey,
                  GroupedKVsAcc, GroupedReds ++ GroupedRedsAcc, KeyGroupFun, Fun, Acc),
          reduce_stream_kp_node2(Bt, Dir, RestNodes, KeyStart, InEndRangeFun, GroupedKey2,
                  GroupedKVsAcc2, GroupedRedsAcc2, KeyGroupFun, Fun, Acc2);
      [] ->
          {ok, Acc, GroupedReds ++ GroupedRedsAcc, GroupedKVsAcc, GroupedKey}
  