anchor.diff:     NewInternal = Internal ++ Call2,
      NewCtx1 = set_variable_tuple_name(NewCtx, NextTupleVar),
      flwor(NewCtx1, T, RetId, Return, NewInternal, 
  -         FunAbs ++ Global,NextTupleVar,false);
  +         FunAbs ++ Global,NextTupleVar,false,Rems);
   
   % group
   flwor(Ctx, [{group_by,Id,_} = F|T], RetId, Return, Internal, 
  -      Global,TupleVar,_Inline) ->
  +      Global,TupleVar,_Inline,[Rem|Rems]) ->
      NextTupleVar = {var,?L,next_var_tuple_name()},
      CurrContext = {var,?L,get_context_variable_name(Ctx)},
      ThisFun = glob_fun_name({group_by,Id}),
  -   {NewCtx,FunAbs} = group_part(Ctx, F),
  +   {NewCtx,FunAbs} = group_part(Ctx, F, Rem),
      Call2 = [?P("_@NextTupleVar = '@ThisFun@'(_@CurrContext,xqerl_seq3:flatten(_@TupleVar))")],
      NewInternal = Internal ++ Call2,
      NewCtx1 = set_variable_tuple_name(NewCtx, NextTupleVar),
      flwor(NewCtx1, T, RetId, Return, NewInternal, 
  -         FunAbs ++ Global,NextTupleVar,false);
  +         FunAbs ++ Global,NextTupleVar,false,Rems);
   
   % order
   flwor(Ctx, [{order_by,Id,_} = F|T], RetId, Return, Internal, 
  -      Global,TupleVar,_Inline) ->
  +      Global,TupleVar,_Inline,[Rem,Rem2|Rems]) ->
      NextTupleVar = {var,?L,next_var_tuple_name()},
      CurrContext = {var,?L,get_context_variable_name(Ctx)},
      ThisFun = glob_fun_name({order_by,Id}),
  
positive.code: expr_do(Ctx, #xqFlwor{id = RetId, loop = Loop, return = Return}) ->
     Ctx1 = Ctx#{grp_variables => []}, % Clear any grouping variables
     VarTup = get_variable_tuple_name(Ctx1),
     {_NewCtx,In,Out} = flwor(Ctx1, Loop, RetId, Return, [], [],VarTup, false),
     add_global_funs(Out),
     %?P("(begin _@In end)");
     ?P("xqerl_seq3:flatten(begin _@In end)");
  
negative.code:                            position = #xqPosVar{id = PId, 
                                                  name = PName},
                             anno = Line},
                AType} = Part, NextFunAtom, IsList, Rem) ->
     _ = set_line(Line),
     VarName = local_variable_name(Id),
     NewVar    = {Name,Type,[],VarName},
  