anchor.diff:     %?dbg("Variables",Variables),
      M1 = lists:foldl(fun({#qname{} = Nm,_,_,_,_}, Map) when IsLib ->
                           digraph:add_vertex(G, {0,sim_name(Nm)}),
  -                        add_edge(G, library,{0,sim_name(Nm)}),
  +                        add_edge(G,{0,sim_name(Nm)}, library),
                           maps:put(sim_name(Nm), 0, Map);
                          ({#qname{} = Nm,_,_,_,_}, Map) ->
                           digraph:add_vertex(G, {0,sim_name(Nm)}),
                           maps:put(sim_name(Nm), 0, Map);
                          (#xqVar{id = Id, name = Nm}, Map) when IsLib ->
                           digraph:add_vertex(G, {Id,sim_name(Nm)}),
  -                        add_edge(G, library,{Id,sim_name(Nm)}),
  +                        add_edge(G, {Id,sim_name(Nm)},library),
                           maps:put(sim_name(Nm), Id, Map);
                          (#xqVar{id = Id, name = Nm}, Map) ->
                           digraph:add_vertex(G, {Id,sim_name(Nm)}),
  
positive.code:    if IsLib ->
           digraph:add_vertex(G, library);
        true ->
           digraph:add_vertex(G, library)
     end,
     %G = digraph:new([acyclic]),
     % add the variables
  
negative.code: 
  has_cycle(G) ->
     Vars = [Var || {I,_} = Var <- digraph:vertices(G), is_integer(I)],
     %?dbg("Vars",Vars),
     lists:foreach(fun(Var) ->
                         case digraph:get_cycle(G, Var) of
                             false ->
  