anchor.diff:      /// <para> inputFilter is a function that is involved in choosing trees.</para>
       /// </summary>
       member this.GetNextTree (unprocessed : Terminal list) inputFilter = 
  -        let processedToks = Array.init tokens.Length (fun i -> not (unprocessed |> List.exists (fun j -> j.TokenNumber = i)))
  +        let processedToks = Array.init tokens.Length (fun i -> unprocessed |> List.forall (fun j -> j.TokenNumber <> i))
           
  -        let rootFamily = 
  -            match root with
  -            | :? AST as ast -> ast
  -            | :? Epsilon -> Unchecked.defaultof<_>
  -            | _ -> failwith "Strange tree - singleNode with non-negative value"
  -
           let processedFamily = new ResizeArray<_>()
   
           let filter family = 
  -            if processedFamily.Contains family 
  -            then false
  -            else inputFilter family
  +            (not <| processedFamily.Contains family) && inputFilter family
   
           /// choose family from AST which contains the more unprocessed tokens.
           /// if filter returns 'false' for all families then ast.first will be returned. 
           let handleAST (ast : AST) = 
  -            if ast.other = null || not <| Seq.exists (fun i -> i = false) processedToks
  +            if ast.other = null || Seq.forall ((<>) false) processedToks
               then 
                   ast.first
  -            else                
  +            else
  +                /// intersects family tokens and unprocessed tokens
  +                /// and returns length of the resulting list
                   let getUnprocessedCount family = 
                       let familyLeaves = 
                           Tree<_>.GetTokensFromFamily family 
                           |> Seq.distinct 
                           |> Seq.toList
  -                    let newToksList = 
  -                        unprocessed 
  -                        |> List.filter 
  -                            (
  -                                fun leaf -> 
  -                                    familyLeaves 
  -                                    |> List.exists (fun x -> x.TokenNumber = leaf.TokenNumber)
  -                            )
  -                    newToksList.Length
  -
  -                let mutable nextFam = ast.first
  -                let mutable maxNewToks = 
  -                    if filter ast.first 
  -                    then getUnprocessedCount ast.first
  -                    else -1
  +                    unprocessed 
  +                    |> List.filter 
  +                        (
  +                            fun leaf -> 
  +                                familyLeaves 
  +                                |> List.exists (fun x -> x.TokenNumber = leaf.TokenNumber)
  +                        )
  +                    |> List.length
  +
  +                let nextFam = ref ast.first
  +                let analyzeFamily = 
  +                    let maxNewToks = 
  +                        if filter ast.first 
  +                        then ref <| getUnprocessedCount ast.first
  +                        else ref -1
  +                    fun family -> 
  +                        let newTokens = getUnprocessedCount family
  +                        if newTokens > !maxNewToks 
  +                        then 
  +                            nextFam := family
  +                            maxNewToks := newTokens
                   
  -                for family in ast.other do
  -                    if filter family
  -                    then 
  -                        let newTokens = getUnprocessedCount family
  -                        if newTokens > maxNewToks 
  -                        then nextFam <- family
  -
  -                nextFam
  +                ast.other
  +                |> Array.filter filter
  +                |> Array.iter analyzeFamily
  +                !nextFam
   
           let rec processFamily (family : Family) = 
               processedFamily.Add family
  
positive.code:             |> Array.fold (fun acc elem -> processElem elem acc) []
  
          // now parameter 'tokens' is all sppf tokens rather than tokens from new tree
          let newTree = new Tree<_> (tokens, tree, rules)
          
          newTree, finalUnprocessed
  
      ///<summary>
      /// Returns all trees that contain some token.
      /// <para> tokenName - name of token </para>
      /// <para> tokRange - range of token </para>
      ///</summary>
      member this.GetForestWithToken tokRange (tokenToRange: 'TokenType -> seq<_>) = 
          let findToken() = 
              let predicate (range : seq<_>) = 
                  tokRange = Seq.head range
                  
              Array.tryFindIndex (fun tok -> 
                              let range = tokenToRange tok
                              predicate range) tokens
  
          let tokNumberOption = findToken()
          if tokNumberOption.IsNone
          then 
              []
          else
              let token = new Terminal(tokNumberOption.Value)
              let forestFam = ref []
              let mutable forestTree = []
              let filter (family : Family) = 
                  let nodes = Tree<_>.GetTokensFromFamily family
                  if List.exists (fun tok -> tok = token) nodes
                  then 
                      not <| List.exists (fun fam -> 
                                          let famNodes = Tree<_>.GetTokensFromFamily fam
                                          let newList = List.filter (fun node1 -> List.exists (fun node2 -> node1 = node2) famNodes) nodes
                                          newList.Length = nodes.Length
                                      ) !forestFam 
                  else false
  
              let filterTree (tree : Tree<_>) = 
                  match tree.Root with
                  | :? AST as ast -> 
                      // I suppose that rootFamily.other is always null. But I'm not sure
                      let res = filter ast.first
                      if res then forestFam := ast.first :: !forestFam
                      res
                  | x -> failwith "Error in GetForestWithToken function. Expected AST as tree.Root but %s was" <| x.GetType().ToString()
  
              let mutable tree = fst <| this.GetNextTree [token] filter
  
              while filterTree tree do
                  forestTree <- tree :: forestTree
                  tree <- fst <| this.GetNextTree [token] filter
          
              forestTree
  
  
negative.code: 
  module Yard.Generators.Common.AST
  open System
  open System.IO
  open System.Collections.Generic
  open Yard.Generators.Common.DataStructures
  open Yard.Generators.Common.AstNode
  