anchor.diff:              ANodesRight1=ANodesRight;
           % In this case we tailoring a new branch by fixing ids of a tree node
           {[#bnode{id=Id1,bnode_ids=Ids}=H|_], [#bnode{id=Id}|_]=LeftRest} ->
  +%%             io:format("~p~n",[{'BNODE-BRANCH',Id1}]),
               PNodesLeft1=PNodesLeft,
  +            BNodeChangeMap1=BNodeChangeMap,
               BNodesRight1=lists:keyreplace(Id1, #bnode.id, BNodesRight, H#bnode{bnode_ids=[Id|Ids]})++LeftRest,
               %% Filter out alpha nodes that point to bnodes trunceted after merge of beta layer
               % Dou to alpha node may have multiple pointers to bnodes we firstly remove that 
  
positive.code:                    Acc#anode{bnode_ids=umerge_lists(Bids, AccBids)}
             end,HAN,Tail) || [HAN|Tail]<-EquimatchComponents],
      % 4. Return resulting rete
      Tree#rete{bnodes=BNodesRight1,anodes=ANodesRight2,pnodes=umerge_lists(PNodesLeft1,PNodesRight)}.
  
  lists_replace(OldElem, NewElem, List) ->
      [if OldElem == Elem ->
  
negative.code:         % In this case we just mark that tree node have an output (pnodes)
          {[#bnode{id=Id,pnodes=PIds}=H|_], []} ->
              #bnode{id=IdL,pnodes=PIdsL}=lists:last(BNodesLeft),
              BNodeChangeMap1=[{IdL, Id}|BNodeChangeMap],
  %%             io:format("~p~n",[{'BNODE',IdL,'->',Id}]),
              % Update pnodes bnode_ids: replace an old bnode id (IdL) with a new one (Id)
              PNodesLeft1=[ P#pnode{bnode_ids=lists_replace(IdL, Id, BIds)} || #pnode{bnode_ids=BIds}=P <-PNodesLeft],
              BNodesRight1=lists:keyreplace(Id, #bnode.id, BNodesRight, H#bnode{pnodes=umerge_lists(PIds,PIdsL)}),
  