anchor.diff:  
   
   winend(SPrev,S,SPos,SNext,[[],{E, EPos},{ENext, _}|_] = L, EndFun, Acc, Only) ->
  +   NewAcc = [E|Acc],
      case bool(EndFun({S,SPos,SPrev,SNext,E,EPos,[],ENext})) of
         true ->
  -         {[{S,SPos,SPrev,SNext,E,EPos,[],ENext, ?seq:append(E, Acc)}], tl(L)};
  -      _ ->
  -         winend(SPrev,S,SPos,SNext,tl(L), EndFun, ?seq:append(E, Acc), Only)
  +         {{S,SPos,SPrev,SNext,E,EPos,[],ENext, lists:reverse(NewAcc)}, tl(L)};
  +      _ ->
  +         winend(SPrev,S,SPos,SNext,tl(L), EndFun, NewAcc, Only)
      end;
   winend(SPrev,S,SPos,SNext,[[],{E, EPos}] = L, EndFun, Acc, Only) ->
  +   NewAcc = [E|Acc],
      case bool(EndFun({S,SPos,SPrev,SNext,E,EPos,[],[]})) of
         true ->
  -         {[{S,SPos,SPrev,SNext,E,EPos,[],[], ?seq:append(E, Acc)}], tl(L)};
  -      _ ->
  -         winend(SPrev,S,SPos,SNext,tl(L), EndFun, ?seq:append(E, Acc), Only)
  +         {{S,SPos,SPrev,SNext,E,EPos,[],[], lists:reverse(NewAcc)}, tl(L)};
  +      _ ->
  +         winend(SPrev,S,SPos,SNext,tl(L), EndFun, NewAcc, Only)
      end;
   winend(SPrev,S,SPos,SNext,[{EPrev,_},{E, EPos}], EndFun, Acc, Only) ->
  +   NewAcc = [E|Acc],
      case bool(EndFun({S,SPos,SPrev,SNext,E,EPos,EPrev,[]})) of
         true ->
  -         {[{S,SPos,SPrev,SNext,E,EPos,EPrev,[], ?seq:append(E, Acc)}], []};
  +         {{S,SPos,SPrev,SNext,E,EPos,EPrev,[], lists:reverse(NewAcc)}, []};
         _ ->
            if Only == true ->
                  {[], []};
               true ->
  -               {[{S,SPos,SPrev,SNext,E,EPos,EPrev,[], ?seq:append(E, Acc)}], []}
  +               {{S,SPos,SPrev,SNext,E,EPos,EPrev,[], lists:reverse(NewAcc)}, []}
            end
      end;
   winend(SPrev,S,SPos,SNext,[{EPrev,_}], EndFun, Acc, Only) ->
      case bool(EndFun({S,SPos,SPrev,SNext,[],[],EPrev,[]})) of
         true ->
  -         {[{S,SPos,SPrev,SNext,[],[],EPrev,[], Acc}], []};
  +         {{S,SPos,SPrev,SNext,[],[],EPrev,[], lists:reverse(Acc)}, []};
         _ ->
            if Only == true ->
                  {[], []};
               true ->
  -               {[{S,SPos,SPrev,SNext,[],[],EPrev,[], Acc}], []}
  +               {{S,SPos,SPrev,SNext,[],[],EPrev,[], lists:reverse(Acc)}, []}
            end
      end;
   winend(SPrev,S,SPos,SNext,[{EPrev,_},{E, EPos},{ENext, _}|_] = L, 
          EndFun, Acc, Only) ->
  +   NewAcc = [E|Acc],
      case bool(EndFun({S,SPos,SPrev,SNext,E,EPos,EPrev,ENext})) of
         true ->
  -         {[{S,SPos,SPrev,SNext,E,EPos,EPrev,ENext, ?seq:append(E, Acc)}], 
  -          tl(L)};
  -      _ ->
  -         winend(SPrev,S,SPos,SNext,tl(L), EndFun, ?seq:append(E, Acc), Only)
  +         {{S,SPos,SPrev,SNext,E,EPos,EPrev,ENext, lists:reverse(NewAcc)}, tl(L)};
  +      _ ->
  +         winend(SPrev,S,SPos,SNext,tl(L), EndFun, NewAcc, Only)
      end.
   
   %% functions for group by
  
positive.code:    lists:map(fun(I) ->
                    lists:flatten(lists:reverse(lists:nth(I, List)))
               end, lists:seq(1, Sz)).
  
  %% int_order_1(Tuple,Clauses) ->
  %%    Cs = lists:map(fun({C,D,E}) ->
  %%                    V = C(Tuple),
  %%                    {V,D,E}
  %%              end, Clauses),
  %%    {Tuple,Cs}.
  %% 
  %% pmap(F, [L1,L2,L3,L4,L5,L6,L7,L8,L9,L10,
  %%          L11,L12,L13,L14,L15,L16,L17,L18,L19,L20|T]) ->
  %%    S = self(),
  %%    Ref = make_ref(),
  %%    Pids = lists:map(fun(I) ->
  %%                           spawn(fun() ->
  %%                                       do_f(S,Ref,F,I) 
  %%                                 end)
  %%                     end, [L1,L2,L3,L4,L5,L6,L7,L8,L9,L10,
  %%          L11,L12,L13,L14,L15,L16,L17,L18,L19,L20]),
  %%    H = gather(Pids,Ref),
  %%    H ++ pmap(F,T);
  %% pmap(F, [L1,L2,L3,L4,L5,L6,L7,L8,L9,L10|T]) ->
  %%    S = self(),
  %%    Ref = make_ref(),
  %%    Pids = lists:map(fun(I) ->
  %%                           spawn(fun() ->
  %%                                       do_f(S,Ref,F,I) 
  %%                                 end)
  %%                     end, [L1,L2,L3,L4,L5,L6,L7,L8,L9,L10]),
  %%    H = gather(Pids,Ref),
  %%    H ++ pmap(F,T);
  %% pmap(F, L) ->
  %%    lists:map(fun(I) ->
  %%                    F(I)
  %%              end,L).
  %% 
  %% do_f(Parent,Ref,F,I) ->
  %%    Parent ! {self(),Ref,F(I)}.
  %% 
  %% gather([Pid|T],Ref) ->
  %%    receive
  %%       {Pid,Ref,Ret} ->
  %%          %?dbg("Ret",Ret),
  %%          [Ret|gather(T,Ref)]
  %%    end;
  %% gather([],_) ->
  %%    [].
  
  
  % Clauses are funs that take an entire VarStream tuple
  orderbyclause(VarStream, Clauses) ->
  
negative.code: % internal use
  %% -export([int_order_1/2]).
     
  add_position(List) when is_list(List) ->
     List1 = xqerl_seq3:to_list(List),
     add_position(List1, 1, []);
  add_position(List) ->
     add_position([List]).
  
  add_position([H|T], Cnt, Acc) ->
     New = {H, ?atint(Cnt)},
     add_position(T, Cnt + 1, [New|Acc]);
  add_position([], _Cnt, Acc) ->
     lists:reverse(Acc).
  
  do_atomize([],_) -> {<<>>, []};
  do_atomize([V],C) -> do_atomize(V,C);
  do_atomize(#{nk := _} = N,Coll) ->
     A = xqerl_seq3:singleton_value(xqerl_types:atomize(N)),
     #xqAtomicValue{value = Val} = A,
     {xqerl_coll:sort_key(Val, Coll), A};
  do_atomize(#xqAtomicValue{value = Val, type = T} = A,_)
  