anchor.diff:      undefined ->
           KVs;
       _ ->
  -        lists:dropwhile(fun({Key,_}) -> less(Bt, Key, KeyStart) end, KVs)
  -    end,
  -    KVs2 =
  -    case KeyEnd of
  -    undefined ->
  -        GTEKeyStartKVs;
  -    _ ->
  -        lists:takewhile(
  -            fun({Key,_}) ->
  -                not less(Bt, KeyEnd, Key)
  -            end, GTEKeyStartKVs)
  -    end,
  -    reduce_stream_kv_node2(Bt, adjust_dir(Dir, KVs2), GroupedKey, GroupedKVsAcc, GroupedRedsAcc,
  +        DropFun = case Dir of
  +        fwd ->
  +            fun({Key, _}) -> less(Bt, Key, KeyStart) end;
  +        rev ->
  +            fun({Key, _}) -> less(Bt, KeyStart, Key) end
  +        end,
  +        lists:dropwhile(DropFun, KVs)
  +    end,
  +    KVs2 = lists:takewhile(
  +        fun({Key, _}) -> InEndRangeFun(Key) end, GTEKeyStartKVs),
  +    reduce_stream_kv_node2(Bt, KVs2, GroupedKey, GroupedKVsAcc, GroupedRedsAcc,
                           KeyGroupFun, Fun, Acc).
   
   
  
positive.code:     end.
  
  
  reduce_stream_node(_Bt, _Dir, nil, _KeyStart, _KeyEnd, GroupedKey, GroupedKVsAcc,
          GroupedRedsAcc, _KeyGroupFun, _Fun, Acc) ->
      {ok, Acc, GroupedRedsAcc, GroupedKVsAcc, GroupedKey};
  reduce_stream_node(Bt, Dir, Node, KeyStart, KeyEnd, 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,
                  GroupedKVsAcc, GroupedRedsAcc, KeyGroupFun, Fun, Acc);
      {kv_node, KVs} ->
          reduce_stream_kv_node(Bt, Dir, KVs, KeyStart, KeyEnd, GroupedKey,
                  GroupedKVsAcc, GroupedRedsAcc, KeyGroupFun, Fun, Acc)
      end.
  
  reduce_stream_kv_node(Bt, Dir, KVs, KeyStart, KeyEnd,
                          GroupedKey, GroupedKVsAcc, GroupedRedsAcc,
                          KeyGroupFun, Fun, Acc) ->
  
  
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}
  