[2.2] New greedy strategy

These changes tries to produce better for patterns with 
cycles, by allowing multiple leaf-nodes for the same 
identifier to be used.