Index: trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/temporalrelation/DefaultEventTargetSequenceDetectionRule.java
===================================================================
--- trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/temporalrelation/DefaultEventTargetSequenceDetectionRule.java	(revision 1099)
+++ trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/temporalrelation/DefaultEventTargetSequenceDetectionRule.java	(revision 1107)
@@ -15,18 +15,48 @@
  * @author 2012, last modified by $Author: patrick$
  */
-public class DefaultEventTargetSequenceDetectionRule implements TemporalRelationshipRule {
+class DefaultEventTargetSequenceDetectionRule implements TemporalRelationshipRule {
 
+    /**
+     * <p>
+     * the task tree node factory to be used for creating substructures for the temporal
+     * relationships identified during rule
+     * </p>
+     */
+    private ITaskTreeNodeFactory taskTreeNodeFactory;
+    /**
+     * <p>
+     * the task tree builder to be used for creating substructures for the temporal relationships
+     * identified during rule application
+     * </p>
+     */
+    private ITaskTreeBuilder taskTreeBuilder;
+    
+    /**
+     * <p>
+     * instantiates the rule with a task tree node factory and builder to be used during rule
+     * application.
+     * </p>
+     * 
+     * @param taskTreeNodeFactory the task tree node factory to be used for creating substructures
+     *                            for the temporal relationships identified during rule
+     *                            application
+     * @param taskTreeBuilder     the task tree builder to be used for creating substructures for
+     *                            the temporal relationships identified during rule application
+     */
+    DefaultEventTargetSequenceDetectionRule(ITaskTreeNodeFactory taskTreeNodeFactory,
+                                            ITaskTreeBuilder     taskTreeBuilder)
+    {
+        this.taskTreeNodeFactory = taskTreeNodeFactory;
+        this.taskTreeBuilder = taskTreeBuilder;
+    }
+    
     /*
      * (non-Javadoc)
      * 
      * @see de.ugoe.cs.tasktree.temporalrelation.TemporalRelationshipRule#apply(TaskTreeNode,
-     * TaskTreeBuilder, TaskTreeNodeFactory)
+     * boolean)
      */
     @Override
-    public RuleApplicationResult apply(ITaskTreeNode        parent,
-                                       ITaskTreeBuilder     builder,
-                                       ITaskTreeNodeFactory nodeFactory,
-                                       boolean              finalize)
-    {
+    public RuleApplicationResult apply(ITaskTreeNode parent, boolean finalize) {
         if (!(parent instanceof ISequence)) {
             return null;
@@ -59,6 +89,6 @@
                         (!(parent.getChildren().get(startingIndex) instanceof ISequence)))
                     {
-                        handleEventTargetSequence(parent, currentEventTarget, startingIndex,
-                                                  endIndex, builder, nodeFactory, result);
+                        handleEventTargetSequence
+                            (parent, currentEventTarget, startingIndex, endIndex, result);
 
                         result.setRuleApplicationStatus
@@ -91,6 +121,6 @@
                      (!(parent.getChildren().get(startingIndex) instanceof ISequence))))
                 {
-                    handleEventTargetSequence(parent, currentEventTarget, startingIndex, endIndex,
-                                              builder, nodeFactory, result);
+                    handleEventTargetSequence
+                        (parent, currentEventTarget, startingIndex, endIndex, result);
                 
                     result.setRuleApplicationStatus(RuleApplicationStatus.RULE_APPLICATION_FINISHED);
@@ -106,8 +136,5 @@
 
     /**
-     * TODO: comment
-     * 
-     * @param child
-     * @return
+     *
      */
     private IEventTarget determineEventTarget(ITaskTreeNode node) {
@@ -134,6 +161,5 @@
 
     /**
-     * TODO: comment
-     * 
+     *
      */
     private void handleEventTargetSequence(ITaskTreeNode         parent,
@@ -141,17 +167,10 @@
                                            int                   startIndex,
                                            int                   endIndex,
-                                           ITaskTreeBuilder      builder,
-                                           ITaskTreeNodeFactory  nodeFactory,
                                            RuleApplicationResult result)
     {
-        ISequence sequence = nodeFactory.createNewSequence();
-        builder.setDescription(sequence, "interactions on " + target.getStringIdentifier());
-
-        for (int i = startIndex; i <= endIndex; i++) {
-            builder.addChild(sequence, parent.getChildren().get(startIndex));
-            builder.removeChild((ISequence) parent, startIndex);
-        }
-
-        builder.addChild((ISequence) parent, startIndex, sequence);
+        String description = "interactions on " + target.getStringIdentifier();
+        
+        ISequence sequence = RuleUtils.createNewSubSequenceInRange
+            (parent, startIndex, endIndex, description, taskTreeNodeFactory, taskTreeBuilder);
 
         result.addNewlyCreatedParentNode(sequence);
Index: trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/temporalrelation/DefaultGuiElementSequenceDetectionRule.java
===================================================================
--- trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/temporalrelation/DefaultGuiElementSequenceDetectionRule.java	(revision 1099)
+++ trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/temporalrelation/DefaultGuiElementSequenceDetectionRule.java	(revision 1107)
@@ -20,6 +20,21 @@
  * @author 2012, last modified by $Author: patrick$
  */
-public class DefaultGuiElementSequenceDetectionRule implements TemporalRelationshipRule {
-
+class DefaultGuiElementSequenceDetectionRule implements TemporalRelationshipRule {
+
+    /**
+     * <p>
+     * the task tree node factory to be used for creating substructures for the temporal
+     * relationships identified during rule
+     * </p>
+     */
+    private ITaskTreeNodeFactory taskTreeNodeFactory;
+    /**
+     * <p>
+     * the task tree builder to be used for creating substructures for the temporal relationships
+     * identified during rule application
+     * </p>
+     */
+    private ITaskTreeBuilder taskTreeBuilder;
+    
     /**
      * <p>
@@ -31,11 +46,20 @@
     /**
      * <p>
-     * instantiates the rule without a GUI element filter
-     * </p>
-     */
-    DefaultGuiElementSequenceDetectionRule() {
-        this.guiElementFilter = null;
-    }
-
+     * instantiates the rule with a task tree node factory and builder to be used during rule
+     * application but without a GUI element filter
+     * </p>
+     * 
+     * @param taskTreeNodeFactory the task tree node factory to be used for creating substructures
+     *                            for the temporal relationships identified during rule
+     *                            application
+     * @param taskTreeBuilder     the task tree builder to be used for creating substructures for
+     *                            the temporal relationships identified during rule application
+     */
+    DefaultGuiElementSequenceDetectionRule(ITaskTreeNodeFactory taskTreeNodeFactory,
+                                           ITaskTreeBuilder     taskTreeBuilder)
+    {
+        this(null, taskTreeNodeFactory, taskTreeBuilder);
+    }
+    
     /**
      * <p>
@@ -45,8 +69,18 @@
      * </p>
      *
-     * @param guiElementFilter the GUI element filter to be applied
-     */
-    DefaultGuiElementSequenceDetectionRule(List<Class<? extends IGUIElement>> guiElementFilter) {
+     * @param guiElementFilter    the GUI element filter to be applied
+     * @param taskTreeNodeFactory the task tree node factory to be used for creating substructures
+     *                            for the temporal relationships identified during rule
+     *                            application
+     * @param taskTreeBuilder     the task tree builder to be used for creating substructures for
+     *                            the temporal relationships identified during rule application
+     */
+    DefaultGuiElementSequenceDetectionRule(List<Class<? extends IGUIElement>> guiElementFilter,
+                                           ITaskTreeNodeFactory taskTreeNodeFactory,
+                                           ITaskTreeBuilder     taskTreeBuilder)
+    {
         this.guiElementFilter = guiElementFilter;
+        this.taskTreeNodeFactory = taskTreeNodeFactory;
+        this.taskTreeBuilder = taskTreeBuilder;
     }
 
@@ -55,12 +89,8 @@
      * 
      * @see de.ugoe.cs.tasktree.temporalrelation.TemporalRelationshipRule#apply(TaskTreeNode,
-     * TaskTreeBuilder, TaskTreeNodeFactory)
+     * boolean)
      */
     @Override
-    public RuleApplicationResult apply(ITaskTreeNode        parent,
-                                       ITaskTreeBuilder     builder,
-                                       ITaskTreeNodeFactory nodeFactory,
-                                       boolean              finalize)
-    {
+    public RuleApplicationResult apply(ITaskTreeNode parent, boolean finalize) {
         if (!(parent instanceof ISequence)) {
             return null;
@@ -95,10 +125,11 @@
         // anything.
         
-        RuleApplicationStatus status;
+        RuleApplicationStatus status = null;
         if (initialHierarchyLevel < maxHierarchyDepth) {
-            status = generateSubSequences(parent, hierarchies, initialHierarchyLevel, finalize,
-                                          builder, nodeFactory, result);
-        }
-        else {
+            status = generateSubSequences
+                (parent, hierarchies, initialHierarchyLevel, finalize, result);
+        }
+        
+        if (status == null) {
             status = RuleApplicationStatus.RULE_NOT_APPLIED;
         }
@@ -121,6 +152,4 @@
      * @param maxHierarchyDepth the maximum hierarchy depth that may apply in this application
      * @param finalize          true, if the application shall be finalized, false else
-     * @param builder           the builder to use for generating the tree structure
-     * @param nodeFactory       the node factory to use for generating the tree structure
      * @param result            the result of the rule application to add newly created parent
      *                          nodes to
@@ -136,6 +165,4 @@
                                                        int                     hierarchyLevel,
                                                        boolean                 finalize,
-                                                       ITaskTreeBuilder        builder,
-                                                       ITaskTreeNodeFactory    nodeFactory,
                                                        RuleApplicationResult   result)
     {
@@ -169,6 +196,6 @@
             }
             else if (nextGuiElementDiffers) {
-                status = condenseSequence(parent, hierarchies, hierarchyLevel, startingIndex,
-                                          index - 1, builder, nodeFactory, result);
+                status = condenseSequence
+                    (parent, hierarchies, hierarchyLevel, startingIndex, index - 1, result);
 
                 if (status != null) {
@@ -195,5 +222,5 @@
                 status = condenseSequence
                     (parent, hierarchies, hierarchyLevel, startingIndex,
-                     parent.getChildren().size() - 1, builder, nodeFactory, result);
+                     parent.getChildren().size() - 1, result);
             }
             else if (status != RuleApplicationStatus.RULE_APPLICATION_FINISHED) {
@@ -225,6 +252,4 @@
      * @param startIndex     the index of the first child belonging to the subgroup
      * @param endIndex       the index of the last child belonging to the subgroup
-     * @param builder        the builder to use for generating the tree structure
-     * @param nodeFactory    the node factory to use for generating the tree structure
      * @param result         the result of the rule application to add newly created parent nodes to
      * 
@@ -238,6 +263,4 @@
                                                    int                     startIndex,
                                                    int                     endIndex,
-                                                   ITaskTreeBuilder        builder,
-                                                   ITaskTreeNodeFactory    nodeFactory,
                                                    RuleApplicationResult   result)
     {
@@ -247,25 +270,25 @@
 
         if (!onlyASingleChildToReduce || !singleChildIsSequence) {
-            ISequence sequence = nodeFactory.createNewSequence();
+            ISequence sequence = taskTreeNodeFactory.createNewSequence();
             
             List<List<IGUIElement>> subHierarchies = new ArrayList<List<IGUIElement>>();
             List<IGUIElement> newHierarchy =
                 hierarchies.get(startIndex).subList(0, hierarchyLevel + 1);
-            builder.setDescription(sequence, "interactions on " +
-                                   newHierarchy.get(newHierarchy.size() - 1).getStringIdentifier());
+            taskTreeBuilder.setDescription
+                (sequence, "interactions on " +
+                 newHierarchy.get(newHierarchy.size() - 1).getStringIdentifier());
 
             for (int i = startIndex; i <= endIndex; i++) {
-                builder.addChild(sequence, parent.getChildren().get(startIndex));
-                builder.removeChild((ISequence) parent, startIndex);
+                taskTreeBuilder.addChild(sequence, parent.getChildren().get(startIndex));
+                taskTreeBuilder.removeChild((ISequence) parent, startIndex);
                 
                 subHierarchies.add(hierarchies.remove(startIndex));
             }
 
-            builder.addChild((ISequence) parent, startIndex, sequence);
+            taskTreeBuilder.addChild((ISequence) parent, startIndex, sequence);
             
             hierarchies.add(startIndex, newHierarchy);
             
-            generateSubSequences
-                (sequence, subHierarchies, hierarchyLevel + 1, true, builder, nodeFactory, result);
+            generateSubSequences(sequence, subHierarchies, hierarchyLevel + 1, true, result);
 
             result.addNewlyCreatedParentNode(sequence);
Index: trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/temporalrelation/DefaultGuiElementSequenceDetectionRuleBad.java
===================================================================
--- trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/temporalrelation/DefaultGuiElementSequenceDetectionRuleBad.java	(revision 1099)
+++ 	(revision )
@@ -1,651 +1,0 @@
-package de.ugoe.cs.autoquest.tasktrees.temporalrelation;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import de.ugoe.cs.autoquest.eventcore.guimodel.IGUIElement;
-import de.ugoe.cs.autoquest.tasktrees.treeifc.IEventTask;
-import de.ugoe.cs.autoquest.tasktrees.treeifc.ISequence;
-import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskTreeBuilder;
-import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskTreeNode;
-import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskTreeNodeFactory;
-
-/**
- * TODO: comment or delete
- * 
- * @version $Revision: $ $Date: 18.03.2012$
- * @author 2012, last modified by $Author: patrick$
- */
-public class DefaultGuiElementSequenceDetectionRuleBad implements TemporalRelationshipRule {
-
-    /**
-     * 
-     */
-    private List<Class<? extends IGUIElement>> guiElementFilter;
-
-    /**
-     * 
-     */
-    DefaultGuiElementSequenceDetectionRuleBad() {
-        this.guiElementFilter = null;
-    }
-
-    /**
-     * 
-     */
-    DefaultGuiElementSequenceDetectionRuleBad(List<Class<? extends IGUIElement>> guiElementFilter) {
-        this.guiElementFilter = guiElementFilter;
-    }
-
-    /*
-     * (non-Javadoc)
-     * 
-     * @see de.ugoe.cs.tasktree.temporalrelation.TemporalRelationshipRule#apply(TaskTreeNode,
-     * TaskTreeBuilder, TaskTreeNodeFactory)
-     */
-    @Override
-    public RuleApplicationResult apply(ITaskTreeNode        parent,
-                                       ITaskTreeBuilder     builder,
-                                       ITaskTreeNodeFactory nodeFactory,
-                                       boolean              finalize)
-    {
-        if (!(parent instanceof ISequence)) {
-            return null;
-        }
-
-        List<ITaskTreeNode> children = parent.getChildren();
-        RuleApplicationResult result = new RuleApplicationResult();
-        
-        IGUIElement lastGuiElement = null;
-        int index = 0;
-        while (index <= children.size()) {
-            ITaskTreeNode child = index < children.size() ? children.get(index) : null;
-            IGUIElement currentGuiElement = getGuiElement(child);
-            if ((index > 0) && (!guiElementsEqual(lastGuiElement, currentGuiElement))) {
-                ReducableCommonDenominator commonDenominator =
-                    getNextReducableCommonDenominator(parent, index - 1);
-                
-                RuleApplicationStatus status = handleCommonDenominator
-                    (commonDenominator, parent, index, lastGuiElement, currentGuiElement, builder,
-                     nodeFactory, finalize, result);
-                
-                if (status != null) {
-                    result.setRuleApplicationStatus(status);
-                    return result;
-                }
-                // else go on
-            }
-
-            lastGuiElement = currentGuiElement;
-            index++;
-        }
-
-        return result;
-    }
-
-    /**
-     * 
-     */
-    private ReducableCommonDenominator getNextReducableCommonDenominator(ITaskTreeNode parent,
-                                                                         int           childIndex)
-    {
-        ReducableCommonDenominator commonDenominator = null;
-        
-        // a common denominator can only exist for at least two task tree nodes
-        if (childIndex > 0) {
-            // start with the last one
-            int pos = childIndex;
-
-            commonDenominator = new ReducableCommonDenominator();
-            
-            // check for further predecessors, if they match the same common denominator
-            IGUIElement currentCommonDenominator = null;
-            do {
-                if (--pos < 0) {
-                    currentCommonDenominator = null;
-                }
-                else {
-                    currentCommonDenominator = getCommonDenominator
-                        (getGuiElement(parent.getChildren().get(pos)),
-                         getGuiElement(parent.getChildren().get(pos + 1)));
-                }
-                
-                if (commonDenominator.commonGuiElement == null) {
-                    commonDenominator.commonGuiElement = currentCommonDenominator;
-                }
-            }
-            while ((commonDenominator.commonGuiElement != null) &&
-                   (commonDenominator.commonGuiElement.equals(currentCommonDenominator)));
-            
-            if (commonDenominator.commonGuiElement != null) {
-                // pos points to the last element, that has not the same common denominator.
-                // This one must be subtracted from the task number as well
-                commonDenominator.noOfTasks = childIndex - pos;
-            }
-            else {
-                commonDenominator = null;
-            }
-        }
-        
-        return commonDenominator;
-    }
-
-    /**
-     * 
-     */
-    private RuleApplicationStatus handleCommonDenominator(ReducableCommonDenominator commonDenominator,
-                                                          ITaskTreeNode              parent,
-                                                          int                        currentIndex,
-                                                          IGUIElement                lastGuiElement,
-                                                          IGUIElement                currentGuiElement,
-                                                          ITaskTreeBuilder           builder,
-                                                          ITaskTreeNodeFactory       nodeFactory,
-                                                          boolean                    finalize,
-                                                          RuleApplicationResult      result)
-    {
-        List<ITaskTreeNode> children = parent.getChildren();
-        
-        boolean sequenceHasOnlyOneChild = children.size() == 1;
-        boolean reachedEndOfSequence = currentIndex == children.size();
-        boolean haveCommonDenominator = commonDenominator != null;
-        boolean allChildrenShareDenominator =
-            haveCommonDenominator && commonDenominator.noOfTasks == children.size();
-        boolean nextChildSharesDenominator =
-            haveCommonDenominator && !reachedEndOfSequence &&
-            isOnGuiElementPath(commonDenominator.commonGuiElement, currentGuiElement);
-        
-        IGUIElement denominatorOfPreviousAndCurrentChild =
-            !reachedEndOfSequence ? getCommonDenominator(lastGuiElement, currentGuiElement) : null;
-        
-        boolean previousAndCurrentChildHaveDenominator =
-            denominatorOfPreviousAndCurrentChild != null;
-
-        if (haveCommonDenominator) {
-            if (!reachedEndOfSequence) {
-                if (nextChildSharesDenominator) {
-                    // the last child, although matching the identified common denominator, may
-                    // stand on its own because it is even deeper in the hierarchy, than the
-                    // common denominator as well as the common denominator with the next child.
-                    // So there need to appropriate subsequences to distinguish the child from
-                    // the hierarchy of the next one.
-                    if (isOnGuiElementPath(denominatorOfPreviousAndCurrentChild, lastGuiElement)) {
-                        return condenseChildToSequencesRepresentingHierarchy
-                            (parent, lastGuiElement, denominatorOfPreviousAndCurrentChild,
-                             currentIndex - 1, builder, nodeFactory, result);
-                    }
-                    else {
-                        // go on
-                        return null;
-                    }
-                }
-                else {
-                    condenseTasksToSequencesRepresentingHierarchy
-                        (commonDenominator.commonGuiElement, currentGuiElement, parent,
-                         currentIndex, commonDenominator.noOfTasks, builder, nodeFactory, result);
-
-                    return RuleApplicationStatus.RULE_APPLICATION_FINISHED;
-                }
-            }
-            else {
-                // end of sequence is reached and denominator is found
-                if (!allChildrenShareDenominator) {
-                    condenseTasksToSequencesRepresentingHierarchy
-                        (commonDenominator.commonGuiElement, currentGuiElement, parent,
-                         currentIndex, commonDenominator.noOfTasks, builder, nodeFactory, result);
-
-                    return RuleApplicationStatus.RULE_APPLICATION_FINISHED;
-                }
-                else {
-                    // all children share denominator
-                    if (finalize) {
-                        if (ensureSequencesRepresentingHierarchy
-                                (parent, commonDenominator.commonGuiElement,
-                                 builder, nodeFactory, result))
-                        {
-                            return RuleApplicationStatus.RULE_APPLICATION_FINISHED;
-                        }
-                        else {
-                            return condenseChildToSequencesRepresentingHierarchy
-                                (parent, lastGuiElement, getGuiElement(parent), currentIndex - 1,
-                                 builder, nodeFactory, result);
-                        }
-                    }
-                    else {
-                        return RuleApplicationStatus.RULE_APPLICATION_FEASIBLE;
-                    }
-                }
-            }
-        }
-        else {
-            // no common denominator found
-            if (!reachedEndOfSequence) {
-                if (previousAndCurrentChildHaveDenominator) {
-                    // go on
-                    return null;
-                }
-                else {
-                    return condenseChildToSequencesRepresentingHierarchy
-                        (parent, lastGuiElement, getGuiElement(parent), currentIndex - 1,
-                         builder, nodeFactory, result);
-                }
-            }
-            else {
-                // last child has its own GUI hierarchy
-                if (sequenceHasOnlyOneChild) {
-                    if (finalize) {
-                        if (ensureSequencesRepresentingHierarchy
-                                (parent, lastGuiElement, builder, nodeFactory, result))
-                        {
-                            return RuleApplicationStatus.RULE_APPLICATION_FINISHED;
-                        }
-                        else {
-                            return RuleApplicationStatus.RULE_NOT_APPLIED;
-                        }
-                    }
-                    else {
-                        return RuleApplicationStatus.RULE_APPLICATION_FEASIBLE;
-                    }
-                }
-                else {
-                    if (finalize) {
-                        return condenseChildToSequencesRepresentingHierarchy
-                            (parent, lastGuiElement, getGuiElement(parent), currentIndex - 1,
-                             builder, nodeFactory, result);
-                    }
-                    else {
-                        return RuleApplicationStatus.RULE_APPLICATION_FEASIBLE;
-                    }
-                }
-            }
-        }
-    }
-
-    /**
-     * 
-     */
-    private IGUIElement getCommonDenominator(List<IGUIElement> guiElements) {
-        IGUIElement commonDenominator = null;
-        
-        if (guiElements.size() > 0) {
-            List<IGUIElement> commonDenominatorPath = new ArrayList<IGUIElement>();
-            
-            // create a reference list using the first GUI element
-            IGUIElement guiElement = guiElements.get(0);
-            while (guiElement != null) {
-                if (guiElementMatchesConsideredTypes(guiElement)) {
-                    commonDenominatorPath.add(0, guiElement);
-                }
-                guiElement = guiElement.getParent();
-            }
-            
-            if (commonDenominatorPath.size() == 0) {
-                return null;
-            }
-            
-            // for each other GUI element, check the reference list for the first element in the
-            // path, that is not common to the current one, and delete it as well as it subsequent
-            // siblings
-            List<IGUIElement> currentPath = new ArrayList<IGUIElement>();
-            for (int i = 1; i < guiElements.size(); i++) {
-                currentPath.clear();
-                guiElement = guiElements.get(i);
-                while (guiElement != null) {
-                    if (guiElementMatchesConsideredTypes(guiElement)) {
-                        currentPath.add(0, guiElement);
-                    }
-                    guiElement = guiElement.getParent();
-                }
-                
-                // determine the index of the first unequal path element
-                int index = 0;
-                while ((index < commonDenominatorPath.size()) && (index < currentPath.size()) &&
-                        commonDenominatorPath.get(index).equals(currentPath.get(index)))
-                {
-                    index++;
-                }
-                
-                // remove all elements from the common denonimator path, that do not match
-                while (index < commonDenominatorPath.size()) {
-                    commonDenominatorPath.remove(index);
-                }
-            }
-            
-            if (commonDenominatorPath.size() > 0) {
-                commonDenominator = commonDenominatorPath.get(commonDenominatorPath.size() - 1);
-            }
-        }
-        
-        return commonDenominator;
-    }
-
-    /**
-     * 
-     */
-    private IGUIElement getCommonDenominator(IGUIElement guiElement1, IGUIElement guiElement2) {
-        if ((guiElement1 == null) || (guiElement2 == null)) {
-            return null;
-        }
-    
-        List<IGUIElement> allGuiElements = new ArrayList<IGUIElement>();
-        allGuiElements.add(guiElement1);
-        allGuiElements.add(guiElement2);
-        return getCommonDenominator(allGuiElements);
-    }
-
-    /**
-     * 
-     */
-    private void condenseTasksToSequencesRepresentingHierarchy(IGUIElement           lastGuiElement,
-                                                               IGUIElement           currentGuiElement,
-                                                               ITaskTreeNode         parent,
-                                                               int                   parentIndex,
-                                                               int                   noOfTasks,
-                                                               ITaskTreeBuilder      builder,
-                                                               ITaskTreeNodeFactory  nodeFactory,
-                                                               RuleApplicationResult result)
-    {
-        List<IGUIElement> lastHierarchy = getGuiElementHierarchy(lastGuiElement);
-        List<IGUIElement> currentHierarchy = getGuiElementHierarchy(currentGuiElement);
-        int index = parentIndex;
-        
-        ITaskTreeNode generatedSequence = parent;
-        
-        for (int i = 0; i < lastHierarchy.size(); i++) {
-            // add sequence for each element in the previous hierarchy, that does not occur in the
-            // current hierarchy
-            if ((currentHierarchy == null) || (i >= currentHierarchy.size()) ||
-                (!currentHierarchy.get(i).equals(lastHierarchy.get(i))))
-            {
-                condenseTasksToSequence(generatedSequence, lastHierarchy.get(i), index,
-                                        noOfTasks, builder, nodeFactory, result);
-                
-                // only in the first iteration, we condense tasks in the parent. Afterwards,
-                // we always condense all tasks in the created sequence to a new subsequence.
-                // Therefore, adapt all indexes appropriately
-                generatedSequence = generatedSequence.getChildren().get(index - noOfTasks);
-                index = noOfTasks;
-            }
-        }
-    }
-
-    /**
-     * 
-     */
-    private boolean ensureSequencesRepresentingHierarchy(ITaskTreeNode         parent,
-                                                         IGUIElement           elementToRepresent,
-                                                         ITaskTreeBuilder      builder,
-                                                         ITaskTreeNodeFactory  nodeFactory,
-                                                         RuleApplicationResult result)
-    {
-        boolean applied = false;
-        IGUIElement currentlyConsideredElement = elementToRepresent;
-        IGUIElement elementRepresentedByParent = getGuiElement(parent);
-
-        while ((currentlyConsideredElement != null) &&
-               (!currentlyConsideredElement.equals(elementRepresentedByParent)))
-        {
-            condenseTasksToSequence(parent, currentlyConsideredElement, parent.getChildren().size(),
-                                    parent.getChildren().size(), builder, nodeFactory, result);
-            applied = true;
-            currentlyConsideredElement = currentlyConsideredElement.getParent();
-        }
-        
-        if (currentlyConsideredElement != null) {
-            applied |= updateDescription(parent, currentlyConsideredElement, builder);
-        }
-        
-        return applied;
-    }
-
-    /**
-     * 
-     */
-    private RuleApplicationStatus condenseChildToSequencesRepresentingHierarchy(ITaskTreeNode         parent,
-                                                                                IGUIElement           childGuiElement,
-                                                                                IGUIElement           parentGuiElement,
-                                                                                int                   childIndex,
-                                                                                ITaskTreeBuilder      builder,
-                                                                                ITaskTreeNodeFactory  nodeFactory,
-                                                                                RuleApplicationResult result)
-    {
-        ITaskTreeNode child = parent.getChildren().get(childIndex);
-        boolean childIsSequence = child instanceof ISequence;
-        boolean childHasGuiElement = childGuiElement != null;
-        
-        if (childIsSequence) {
-            if (childHasGuiElement) {
-                if (updateDescription(child, childGuiElement, builder)) {
-                    return RuleApplicationStatus.RULE_APPLICATION_FINISHED;
-                }
-            }
-        }
-        else {
-            boolean applied = false;
-            IGUIElement currentlyConsideredElement = childGuiElement;
-
-            while ((currentlyConsideredElement != null) &&
-                   (!currentlyConsideredElement.equals(parentGuiElement)))
-            {
-                condenseTasksToSequence(parent, currentlyConsideredElement, childIndex + 1, 1,
-                                        builder, nodeFactory, result);
-                applied = true;
-                currentlyConsideredElement = currentlyConsideredElement.getParent();
-            }
-            
-            if (currentlyConsideredElement != null) {
-                IGUIElement parentCommonDenominator = getGuiElement(parent);
-                if (currentlyConsideredElement.equals(parentCommonDenominator)) {
-                    applied |= updateDescription(parent, currentlyConsideredElement, builder);
-                }
-            }
-
-            if (applied) {
-                return RuleApplicationStatus.RULE_APPLICATION_FINISHED;
-            }
-        }
-        
-        return null;
-    }
-
-    /**
-     * <p>
-     * condensed a subsequence of the children of the provided parent to a sequence. The
-     * subsequence in the list of children defined by the index of the succeeding child
-     * (parentIndex) and the number of tasks to be condensed (noOfTasks).
-     * </p>
-     *
-     * @param parent      the parent node whose children are to be condensed
-     * @param target      the GUI element in which all condensed interactions take place
-     * @param parentIndex the index of the child in the parent, which follows the children
-     *                    to be condensed
-     * @param noOfTasks   the number of children to be condensed
-     * @param builder     the builder to create the new subsequence
-     * @param nodeFactory the node factory to instantiate the new subsequence
-     * @param result      the result of the rule application to store newly created parent nodes
-     */
-    private void condenseTasksToSequence(ITaskTreeNode         parent,
-                                         IGUIElement           target,          
-                                         int                   parentIndex,
-                                         int                   noOfTasks,
-                                         ITaskTreeBuilder      builder,
-                                         ITaskTreeNodeFactory  nodeFactory,
-                                         RuleApplicationResult result)
-    {
-        ISequence newSequence = nodeFactory.createNewSequence();
-        updateDescription(newSequence, target, builder);
-        
-        for (int i = 0; i < noOfTasks; i++) {
-            builder.addChild(newSequence, parent.getChildren().get(parentIndex - noOfTasks));
-            // remove exactly the same number of children from the parent.
-            builder.removeChild((ISequence) parent, parentIndex - noOfTasks);
-        }
-                
-        builder.addChild((ISequence) parent, parentIndex - noOfTasks, newSequence);
-        result.addNewlyCreatedParentNode(newSequence);
-    }
-
-    /**
-     * 
-     */
-    private boolean updateDescription(ITaskTreeNode    node,
-                                      IGUIElement      commonGuiElement,
-                                      ITaskTreeBuilder builder)
-    {
-        String newDescription = "interactions on " + commonGuiElement.getStringIdentifier();
-
-        String currentDescription = node.getDescription();
-        
-        if ((currentDescription == null) || (currentDescription.indexOf(newDescription) == -1)) {
-            if ((currentDescription != null) && (!"".equals(currentDescription))) {
-                newDescription = currentDescription + "; " + newDescription;
-            }
-            
-            builder.setDescription(node, newDescription);
-            return true;
-        }
-        else {
-            return false;
-        }
-    }
-
-    /**
-     * 
-     */
-    private IGUIElement getGuiElement(ITaskTreeNode node) {
-        if (node != null) {
-            List<IGUIElement> terminalGuiElements = new ArrayList<IGUIElement>();
-            getTerminalGuiElements(node, terminalGuiElements);
-            return getCommonDenominator(terminalGuiElements);
-        }
-        else {
-            return null;
-        }
-    }
-        
-    /**
-     * 
-     */
-    private void getTerminalGuiElements(ITaskTreeNode node, List<IGUIElement> terminalGuiElements) {
-        if (node instanceof IEventTask) {
-            if (((IEventTask) node).getEventTarget() instanceof IGUIElement) {
-                IGUIElement terminalGuiElement = (IGUIElement) ((IEventTask) node).getEventTarget();
-                terminalGuiElement =
-                    searchHierarchyForGuiElementWithConsideredType(terminalGuiElement);
-                
-                if (terminalGuiElement != null) {
-                    terminalGuiElements.add(terminalGuiElement);
-                }
-            }
-        }
-        else {
-            for (ITaskTreeNode child : node.getChildren()) {
-                getTerminalGuiElements(child, terminalGuiElements);
-            }
-        }
-    }
-
-    /**
-     * 
-     */
-    private List<IGUIElement> getGuiElementHierarchy(IGUIElement guiElement) {
-        IGUIElement element = guiElement;
-        
-        if (!guiElementMatchesConsideredTypes(element)) {
-            element = searchHierarchyForGuiElementWithConsideredType(element);
-        }
-        
-        List<IGUIElement> hierarchy = new ArrayList<IGUIElement>();
-        
-        while (element != null) {
-            hierarchy.add(0, element);
-            element = searchHierarchyForGuiElementWithConsideredType(element.getParent());
-        }
-        
-        if (hierarchy.size() > 0) {
-            return hierarchy;
-        }
-        else {
-            return null;
-        }
-    }
-
-    /**
-     * 
-     */
-    private IGUIElement searchHierarchyForGuiElementWithConsideredType(IGUIElement guiElement) {
-        IGUIElement returnValue = guiElement;
-        
-        while ((returnValue != null) && !guiElementMatchesConsideredTypes(returnValue)) {
-            returnValue = returnValue.getParent();
-        }
-        
-        return returnValue;
-    }
-
-    /**
-     * 
-     */
-    private boolean guiElementsEqual(IGUIElement guiElement1, IGUIElement guiElement2) {
-        if (guiElement1 == null) {
-            return guiElement2 == null;
-        }
-        else {
-            return guiElement1.equals(guiElement2);
-        }
-    }
-
-    /**
-     * 
-     */
-    private boolean isOnGuiElementPath(IGUIElement potentialPathElement, IGUIElement child) {
-        IGUIElement guiElement = child;
-        
-        while (guiElement != null) {
-            if (guiElement.equals(potentialPathElement)) {
-                return true;
-            }
-            guiElement = guiElement.getParent();
-        }
-        
-        return false;
-    }
-
-    /**
-     * 
-     */
-    private boolean guiElementMatchesConsideredTypes(IGUIElement guiElement) {
-        if (guiElementFilter == null) {
-            return true;
-        }
-        else {
-            for (Class<? extends IGUIElement> clazz : guiElementFilter) {
-                if (clazz.isInstance(guiElement)) {
-                    return true;
-                }
-            }
-            
-            return false;
-        }
-    }
-
-    /**
-     * 
-     */
-    static class ReducableCommonDenominator {
-        
-        /** the GUI element being the common denominator */
-        IGUIElement commonGuiElement;
-        
-        /** the number of tasks that match the common denominator */
-        int noOfTasks;
-
-        /* (non-Javadoc)
-         * @see java.lang.Object#toString()
-         */
-        @Override
-        public String toString() {
-            return noOfTasks + " tasks on " + commonGuiElement;
-        }
-        
-    }
-}
Index: trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/temporalrelation/DefaultGuiEventSequenceDetectionRule.java
===================================================================
--- trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/temporalrelation/DefaultGuiEventSequenceDetectionRule.java	(revision 1099)
+++ trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/temporalrelation/DefaultGuiEventSequenceDetectionRule.java	(revision 1107)
@@ -1,3 +1,5 @@
 package de.ugoe.cs.autoquest.tasktrees.temporalrelation;
+
+import java.util.Stack;
 
 import de.ugoe.cs.autoquest.eventcore.gui.IInteraction;
@@ -18,18 +20,48 @@
  * @author 2012, last modified by $Author: patrick$
  */
-public class DefaultGuiEventSequenceDetectionRule implements TemporalRelationshipRule {
+class DefaultGuiEventSequenceDetectionRule implements TemporalRelationshipRule {
 
+    /**
+     * <p>
+     * the task tree node factory to be used for creating substructures for the temporal
+     * relationships identified during rule
+     * </p>
+     */
+    private ITaskTreeNodeFactory taskTreeNodeFactory;
+    /**
+     * <p>
+     * the task tree builder to be used for creating substructures for the temporal relationships
+     * identified during rule application
+     * </p>
+     */
+    private ITaskTreeBuilder taskTreeBuilder;
+    
+    /**
+     * <p>
+     * instantiates the rule with a task tree node factory and builder to be used during rule
+     * application.
+     * </p>
+     * 
+     * @param taskTreeNodeFactory the task tree node factory to be used for creating substructures
+     *                            for the temporal relationships identified during rule
+     *                            application
+     * @param taskTreeBuilder     the task tree builder to be used for creating substructures for
+     *                            the temporal relationships identified during rule application
+     */
+    DefaultGuiEventSequenceDetectionRule(ITaskTreeNodeFactory taskTreeNodeFactory,
+                                         ITaskTreeBuilder     taskTreeBuilder)
+    {
+        this.taskTreeNodeFactory = taskTreeNodeFactory;
+        this.taskTreeBuilder = taskTreeBuilder;
+    }
+    
     /*
      * (non-Javadoc)
      * 
      * @see de.ugoe.cs.tasktree.temporalrelation.TemporalRelationshipRule#apply(TaskTreeNode,
-     * TaskTreeBuilder, TaskTreeNodeFactory)
+     * boolean)
      */
     @Override
-    public RuleApplicationResult apply(ITaskTreeNode        parent,
-                                       ITaskTreeBuilder     builder,
-                                       ITaskTreeNodeFactory nodeFactory,
-                                       boolean              finalize)
-    {
+    public RuleApplicationResult apply(ITaskTreeNode parent, boolean finalize) {
         if (!(parent instanceof ISequence)) {
             return null;
@@ -37,5 +69,5 @@
 
         RuleApplicationResult result = new RuleApplicationResult();
-        int sequenceStartingIndex = -1;
+        Stack<Integer> sequenceStartingIndex = new Stack<Integer>();
 
         int index = 0;
@@ -47,68 +79,11 @@
             {
                 IInteraction eventType = (IInteraction) ((IEventTask) child).getEventType();
-                
-                if (eventType.finishesLogicalSequence() && (sequenceStartingIndex > -1))
-                {
-                    // There are several situations in which this implementation may cause infinite
-                    // loops. This is because the rule manager will reapply rules until
-                    // no rule is applied anymore. A sequence identified in a first iteration will
-                    // be identified as a sequence also in a second iteration. As an example
-                    // many sequences start with an interaction starting that sequence and end
-                    // with an interaction ending that sequence. This will be reidentified as
-                    // further subsequence. It must therefore be assured, that a sequence, that
-                    // was once identified is not reidentified in a further application of the rule.
-                    // For this, the implementation performs a kind of dry run. It creates a list of
-                    // children that would belong to an identified sequence. Only if this list is
-                    // not a reidentification then a new sequence is created and added to the
-                    // parent. If it is a reidentification can be identified, if the list of
-                    // children will contain all children of the parent, or if the list of children
-                    // only consists of one sequence. Further, an identified sequence must at least
-                    // have one child.
-                    if (((sequenceStartingIndex != 0) ||
-                         (index != (parent.getChildren().size() - 1))) &&
-                        (((index - sequenceStartingIndex) > 0) ||
-                          (((index - sequenceStartingIndex) == 0) &&
-                           (!eventType.startsLogicalSequence()))))
-                    {
-                        boolean allNewChildrenAreSequences = true;
 
-                        for (int j = sequenceStartingIndex;
-                             ((allNewChildrenAreSequences) && (j < index)); j++)
-                        {
-                            allNewChildrenAreSequences &=
-                                (parent.getChildren().get(j) instanceof ISequence);
-                        }
-
-                        if (!allNewChildrenAreSequences) {
-                            ISequence sequence = nodeFactory.createNewSequence();
-
-                            for (int j = sequenceStartingIndex; j < index; j++) {
-                                builder.addChild
-                                    (sequence, parent.getChildren().get(sequenceStartingIndex));
-                                builder.removeChild((ISequence) parent, sequenceStartingIndex);
-                            }
-
-                            if (!eventType.startsLogicalSequence()) {
-                                builder.addChild
-                                    (sequence, parent.getChildren().get(sequenceStartingIndex));
-                                builder.removeChild((ISequence) parent, sequenceStartingIndex);
-                            }
-
-                            builder.addChild((ISequence) parent, sequenceStartingIndex, sequence);
-
-                            result.addNewlyCreatedParentNode(sequence);
-                            
-                            builder.setDescription
-                                (sequence, "logical sequence started by the first event");
-                            
-                            result.setRuleApplicationStatus
-                                (RuleApplicationStatus.RULE_APPLICATION_FINISHED);
-                            return result;
-                        }
-                    }
+                if (eventType.finishesLogicalSequence() && (sequenceStartingIndex.size() > 0)) {
+                    index = handleLogicalSequence(sequenceStartingIndex, index, parent, result);
                 }
 
                 if (eventType.startsLogicalSequence()) {
-                    sequenceStartingIndex = index;
+                    sequenceStartingIndex.push(index);
                 }
             }
@@ -117,6 +92,16 @@
         }
 
-        if (sequenceStartingIndex >= 0) {
-            result.setRuleApplicationStatus(RuleApplicationStatus.RULE_APPLICATION_FEASIBLE);
+        if (sequenceStartingIndex.size() > 0) {
+            if (!finalize) {
+                result.setRuleApplicationStatus(RuleApplicationStatus.RULE_APPLICATION_FEASIBLE);
+            }
+            else {
+                ITaskTreeNode lastChild = parent.getChildren().get(parent.getChildren().size() - 1);
+                
+                if (lastChild instanceof IEventTask) {
+                    handleLogicalSequence
+                        (sequenceStartingIndex, parent.getChildren().size() - 1, parent, result);
+                }
+            }
         }
 
@@ -124,3 +109,69 @@
     }
 
+    /**
+     * <p>
+     * TODO: comment
+     * </p>
+     *
+     */
+    private int handleLogicalSequence(Stack<Integer>        sequenceStartingIndex,
+                                      int                   index,
+                                      ITaskTreeNode         parent,
+                                      RuleApplicationResult result)
+    {
+        int newIndex = index;
+        IInteraction eventType =
+            (IInteraction) ((IEventTask) parent.getChildren().get(index)).getEventType();
+
+        // There are several situations in which this implementation may cause infinite
+        // loops. This is because the rule manager will reapply rules until
+        // no rule is applied anymore. A sequence identified in a first iteration will
+        // be identified as a sequence also in a second iteration. As an example
+        // many sequences start with an interaction starting that sequence and end
+        // with an interaction ending that sequence. This will be reidentified as
+        // further subsequence. It must therefore be assured, that a sequence, that
+        // was once identified is not reidentified in a further application of the rule.
+        // For this, the implementation performs a kind of dry run. It creates a list of
+        // children that would belong to an identified sequence. Only if this list is
+        // not a reidentification then a new sequence is created and added to the
+        // parent. If it is a reidentification can be identified, if the list of
+        // children will contain all children of the parent, or if the list of children
+        // only consists of one sequence. Further, an identified sequence must at least
+        // have one child.
+        
+        boolean allChildrenBelongToSubSequence =
+            (sequenceStartingIndex.peek() == 0) && (index == (parent.getChildren().size() - 1));
+        
+        boolean atLeastOneChildToCondense = index - sequenceStartingIndex.peek() > 0;
+        
+        if (!allChildrenBelongToSubSequence && atLeastOneChildToCondense) {
+            int startIndex = sequenceStartingIndex.pop();
+            ISequence sequence = taskTreeNodeFactory.createNewSequence();
+
+            for (int j = startIndex; j < index; j++) {
+                taskTreeBuilder.addChild(sequence, parent.getChildren().get(startIndex));
+                taskTreeBuilder.removeChild((ISequence) parent, startIndex);
+            }
+
+            if (!eventType.startsLogicalSequence()) {
+                taskTreeBuilder.addChild(sequence, parent.getChildren().get(startIndex));
+                taskTreeBuilder.removeChild((ISequence) parent, startIndex);
+                newIndex = startIndex;
+            }
+            else {
+                newIndex = startIndex + 1;
+            }
+
+            taskTreeBuilder.addChild((ISequence) parent, startIndex, sequence);
+
+            result.addNewlyCreatedParentNode(sequence);
+                
+            taskTreeBuilder.setDescription(sequence, "logical sequence started by the first event");
+                
+            result.setRuleApplicationStatus(RuleApplicationStatus.RULE_APPLICATION_FINISHED);
+        }
+        
+        return newIndex;
+    }
+
 }
Index: trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/temporalrelation/DefaultIterationDetectionRule.java
===================================================================
--- trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/temporalrelation/DefaultIterationDetectionRule.java	(revision 1099)
+++ trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/temporalrelation/DefaultIterationDetectionRule.java	(revision 1107)
@@ -61,10 +61,30 @@
  * @author Patrick Harms
  */
-public class DefaultIterationDetectionRule implements TemporalRelationshipRule {
-    
+class DefaultIterationDetectionRule implements TemporalRelationshipRule {
+
+    /**
+     * <p>
+     * the maximum length for iterated sequences
+     * </p>
+     */
     private static final int MAX_LENGTH_OF_ITERATED_SEQUENCE = 50;
     
     /**
      * <p>
+     * the task tree node factory to be used for creating substructures for the temporal
+     * relationships identified during rule
+     * </p>
+     */
+    private ITaskTreeNodeFactory taskTreeNodeFactory;
+    /**
+     * <p>
+     * the task tree builder to be used for creating substructures for the temporal relationships
+     * identified during rule application
+     * </p>
+     */
+    private ITaskTreeBuilder taskTreeBuilder;
+
+    /**
+     * <p>
      * the node equality manager needed for comparing task tree nodes with each other
      * </p>
@@ -87,9 +107,12 @@
      */
     DefaultIterationDetectionRule(NodeEqualityRuleManager nodeEqualityRuleManager,
-                                  NodeEquality            minimalNodeEquality)
+                                  NodeEquality            minimalNodeEquality,
+                                  ITaskTreeNodeFactory    taskTreeNodeFactory,
+                                  ITaskTreeBuilder        taskTreeBuilder)
     {
-        super();
         this.nodeEqualityRuleManager = nodeEqualityRuleManager;
         this.minimalNodeEquality = minimalNodeEquality;
+        this.taskTreeNodeFactory = taskTreeNodeFactory;
+        this.taskTreeBuilder = taskTreeBuilder;
     }
 
@@ -97,12 +120,9 @@
      * (non-Javadoc)
      * 
-     * @see TemporalRelationshipRule#apply(TaskTreeNode, TaskTreeBuilder, TaskTreeNodeFactory)
+     * @see de.ugoe.cs.tasktree.temporalrelation.TemporalRelationshipRule#apply(TaskTreeNode,
+     * boolean)
      */
     @Override
-    public RuleApplicationResult apply(ITaskTreeNode        parent,
-                                       ITaskTreeBuilder     treeBuilder,
-                                       ITaskTreeNodeFactory nodeFactory,
-                                       boolean              finalize)
-    {
+    public RuleApplicationResult apply(ITaskTreeNode parent, boolean finalize) {
         if (!(parent instanceof ISequence)) {
             return null;
@@ -122,12 +142,12 @@
         
         
-        SubSequences subSequences = getEqualSubsequences(parent, treeBuilder, nodeFactory);
+        SubSequences subSequences = getEqualSubsequences(parent);
 
         if (subSequences != null) {
             RuleApplicationResult result = new RuleApplicationResult();
 
-            mergeEqualNodes(subSequences.equalVariants, treeBuilder, nodeFactory);
-            IIteration newIteration = createIterationBasedOnIdentifiedVariants
-                (subSequences, treeBuilder, nodeFactory, result);
+            mergeEqualNodes(subSequences.equalVariants);
+            IIteration newIteration =
+                createIterationBasedOnIdentifiedVariants(subSequences, result);
 
             determineNewlyCreatedParentTasks(parent, newIteration, result);
@@ -135,9 +155,9 @@
             // remove iterated children
             for (int j = subSequences.start; j < subSequences.end; j++) {
-                treeBuilder.removeChild((ISequence) parent, subSequences.start);
+                taskTreeBuilder.removeChild((ISequence) parent, subSequences.start);
             }
 
             // add the new iteration instead
-            treeBuilder.addChild((ISequence) parent, subSequences.start, newIteration);
+            taskTreeBuilder.addChild((ISequence) parent, subSequences.start, newIteration);
 
             result.setRuleApplicationStatus(RuleApplicationStatus.RULE_APPLICATION_FINISHED);
@@ -161,6 +181,4 @@
      * 
      * @param parent      the parent node in which iterations of children shall be found
-     * @param treeBuilder the tree builder that can be used for connecting task tree nodes
-     * @param nodeFactory the node factory that can be used for instantiating task tree nodes
      * 
      * @return the iterated subsequences identified in a specific part (contains the equal
@@ -168,8 +186,5 @@
      *         subpart in which the sequences were found) 
      */
-    private SubSequences getEqualSubsequences(ITaskTreeNode        parent,
-                                              ITaskTreeBuilder     treeBuilder,
-                                              ITaskTreeNodeFactory nodeFactory)
-    {
+    private SubSequences getEqualSubsequences(ITaskTreeNode parent) {
         SubSequences subSequences = null;
 
@@ -184,6 +199,5 @@
 
                 boolean foundFurtherVariants = findFurtherVariants
-                    (subSequences, parent, start, end, treeBuilder, nodeFactory,
-                     useEqualSublistLengths);
+                    (subSequences, parent, start, end, useEqualSublistLengths);
 
                 if (foundFurtherVariants) {
@@ -247,8 +261,4 @@
      * @param end                    the end index (exclusive) of the current subpart of children
      *                               in which iterations are searched for
-     * @param treeBuilder            the tree builder that can be used for connecting task tree
-     *                               nodes
-     * @param nodeFactory            the node factory that can be used for instantiating task tree
-     *                               nodes
      * @param useEqualSublistLengths true if the sublists to be searched for all need to have the
      *                               same length
@@ -260,6 +270,4 @@
                                         int                  start,
                                         int                  end,
-                                        ITaskTreeBuilder     treeBuilder,
-                                        ITaskTreeNodeFactory nodeFactory,
                                         boolean              useEqualSublistLengths)
     {
@@ -279,8 +287,8 @@
             }
             
-            ISequence furtherVariant = nodeFactory.createNewSequence();
+            ISequence furtherVariant = taskTreeNodeFactory.createNewSequence();
             
             for (int j = start; j < start + childCount; j++) {
-                treeBuilder.addChild(furtherVariant, parent.getChildren().get(j));
+                taskTreeBuilder.addChild(furtherVariant, parent.getChildren().get(j));
             }
             
@@ -305,6 +313,5 @@
                 
                 foundFurtherVariants = findFurtherVariants
-                    (subSequences, parent, start + childCount, end, treeBuilder, nodeFactory,
-                     useEqualSublistLengths);
+                    (subSequences, parent, start + childCount, end, useEqualSublistLengths);
 
                 if (foundFurtherVariants) {
@@ -331,11 +338,6 @@
      *
      * @param nodes       the list of nodes to be merged
-     * @param treeBuilder the tree builder that can be used for connecting task tree nodes
-     * @param nodeFactory the node factory that can be used for instantiating task tree nodes
-     */
-    private void mergeEqualNodes(List<ITaskTreeNode>   nodes,
-                                 ITaskTreeBuilder      treeBuilder,
-                                 ITaskTreeNodeFactory  nodeFactory)
-    {
+     */
+    private void mergeEqualNodes(List<ITaskTreeNode> nodes) {
         int index1 = 0;
         int index2 = 0;
@@ -349,6 +351,5 @@
             while (index2 < nodes.size()) {
                 variant2 = nodes.get(index2);
-                ITaskTreeNode mergedChild =
-                    mergeEqualTasks(variant1, variant2, treeBuilder, nodeFactory);
+                ITaskTreeNode mergedChild = mergeEqualTasks(variant1, variant2);
                 
                 if (mergedChild != null) {
@@ -382,53 +383,42 @@
      * @param node1       the first task to be merged
      * @param node2       the second task to be merged
-     * @param treeBuilder the tree builder that can be used for connecting task tree nodes
-     * @param nodeFactory the node factory that can be used for instantiating task tree nodes
      * 
      * @return the result of the merge
      */
-    private ITaskTreeNode mergeEqualTasks(ITaskTreeNode         node1,
-                                          ITaskTreeNode         node2,
-                                          ITaskTreeBuilder      treeBuilder,
-                                          ITaskTreeNodeFactory  nodeFactory)
-    {
+    private ITaskTreeNode mergeEqualTasks(ITaskTreeNode node1, ITaskTreeNode node2) {
         ITaskTreeNode mergeResult = null;
         
         if ((node1 instanceof ISequence) && (node2 instanceof ISequence)) {
-            mergeResult = mergeEqualSequences
-                ((ISequence) node1, (ISequence) node2, treeBuilder, nodeFactory);
+            mergeResult = mergeEqualSequences((ISequence) node1, (ISequence) node2);
         }
         else if ((node1 instanceof ISelection) && (node2 instanceof ISelection)) {
-            mergeResult = mergeEqualSelections
-                ((ISelection) node1, (ISelection) node2, treeBuilder, nodeFactory);
+            mergeResult = mergeEqualSelections((ISelection) node1, (ISelection) node2);
         }
         else if ((node1 instanceof IIteration) && (node2 instanceof IIteration)) {
-            mergeResult = mergeEqualIterations
-                ((IIteration) node1, (IIteration) node2, treeBuilder, nodeFactory);
+            mergeResult = mergeEqualIterations((IIteration) node1, (IIteration) node2);
         }
         else if (node1 instanceof ISelection) {
-            treeBuilder.addChild((ISelection) node1, node2);
+            taskTreeBuilder.addChild((ISelection) node1, node2);
             mergeResult = node1;
         }
         else if (node2 instanceof ISelection) {
-            treeBuilder.addChild((ISelection) node2, node1);
+            taskTreeBuilder.addChild((ISelection) node2, node1);
             mergeResult = node2;
         }
         else if (node1 instanceof IIteration) {
-            mergeResult = mergeEqualTasks
-                (((IIteration) node1).getChildren().get(0), node2, treeBuilder, nodeFactory);
+            mergeResult = mergeEqualTasks(((IIteration) node1).getChildren().get(0), node2);
             
             if (mergeResult != null) {
-                IIteration iteration = nodeFactory.createNewIteration();
-                treeBuilder.setChild(iteration, mergeResult);
+                IIteration iteration = taskTreeNodeFactory.createNewIteration();
+                taskTreeBuilder.setChild(iteration, mergeResult);
                 mergeResult = iteration;
             }
         }
         else if (node2 instanceof IIteration) {
-            mergeResult = mergeEqualTasks
-                (((IIteration) node2).getChildren().get(0), node1, treeBuilder, nodeFactory);
+            mergeResult = mergeEqualTasks(((IIteration) node2).getChildren().get(0), node1);
             
             if (mergeResult != null) {
-                IIteration iteration = nodeFactory.createNewIteration();
-                treeBuilder.setChild(iteration, mergeResult);
+                IIteration iteration = taskTreeNodeFactory.createNewIteration();
+                taskTreeBuilder.setChild(iteration, mergeResult);
                 mergeResult = iteration;
             }
@@ -443,7 +433,7 @@
 
         if (mergeResult == null) {
-            mergeResult = nodeFactory.createNewSelection();
-            treeBuilder.addChild((ISelection) mergeResult, node1);
-            treeBuilder.addChild((ISelection) mergeResult, node2);
+            mergeResult = taskTreeNodeFactory.createNewSelection();
+            taskTreeBuilder.addChild((ISelection) mergeResult, node1);
+            taskTreeBuilder.addChild((ISelection) mergeResult, node2);
         }
         
@@ -463,26 +453,19 @@
      * @param sequence1   the first sequence to be merged
      * @param sequence2   the second sequence to be merged
-     * @param treeBuilder the tree builder that can be used for connecting task tree nodes
-     * @param nodeFactory the node factory that can be used for instantiating task tree nodes
      * 
      * @return the result of the merge or null if merging was not possible
      */
-    private ISequence mergeEqualSequences(ISequence             sequence1,
-                                          ISequence             sequence2,
-                                          ITaskTreeBuilder      treeBuilder,
-                                          ITaskTreeNodeFactory  nodeFactory)
-    {
+    private ISequence mergeEqualSequences(ISequence sequence1, ISequence sequence2) {
         ISequence mergeResult = null;
         
         if (sequence1.getChildren().size() == sequence2.getChildren().size()) {
-            mergeResult = nodeFactory.createNewSequence();
+            mergeResult = taskTreeNodeFactory.createNewSequence();
             
             for (int i = 0; i < sequence1.getChildren().size(); i++) {
                 ITaskTreeNode mergedNode = mergeEqualTasks
-                    (sequence1.getChildren().get(i), sequence2.getChildren().get(i),
-                     treeBuilder, nodeFactory);
+                    (sequence1.getChildren().get(i), sequence2.getChildren().get(i));
                 
                 if (mergedNode != null) {
-                    treeBuilder.addChild(mergeResult, mergedNode);
+                    taskTreeBuilder.addChild(mergeResult, mergedNode);
                 }
                 else {
@@ -506,14 +489,8 @@
      * @param selection1  the first selection to be merged
      * @param selection2  the second selection to be merged
-     * @param treeBuilder the tree builder that can be used for connecting task tree nodes
-     * @param nodeFactory the node factory that can be used for instantiating task tree nodes
      * 
      * @return the result of the merge which is never null
      */
-    private ITaskTreeNode mergeEqualSelections(ISelection            selection1,
-                                               ISelection            selection2,
-                                               ITaskTreeBuilder      treeBuilder,
-                                               ITaskTreeNodeFactory  nodeFactory)
-    {
+    private ITaskTreeNode mergeEqualSelections(ISelection selection1, ISelection selection2) {
         ISelection mergeResult = selection1;
         
@@ -526,6 +503,5 @@
             childToMerge = selection2.getChildren().get(i);
             for (int j = 0; j < selection1.getChildren().size(); j++) {
-                mergedChild = mergeEqualTasks
-                    (selection1.getChildren().get(j), childToMerge, treeBuilder, nodeFactory);
+                mergedChild = mergeEqualTasks(selection1.getChildren().get(j), childToMerge);
                 
                 // a merge must not be a selection, except it is one of the children. Otherwise
@@ -538,6 +514,6 @@
                     // we found a real merge. So replace the original child in selection 1 with
                     // the merged child
-                    treeBuilder.removeChild(selection1, selection1.getChildren().get(j));
-                    treeBuilder.addChild(selection1, mergedChild);
+                    taskTreeBuilder.removeChild(selection1, selection1.getChildren().get(j));
+                    taskTreeBuilder.addChild(selection1, mergedChild);
                     mergedChild = null;
                     childToMerge = null;
@@ -547,5 +523,5 @@
             
             if (childToMerge != null) {
-                treeBuilder.addChild(selection1, childToMerge);
+                taskTreeBuilder.addChild(selection1, childToMerge);
             }
         }
@@ -563,23 +539,16 @@
      * @param selection1  the first iteration to be merged
      * @param selection2  the second iteration to be merged
-     * @param treeBuilder the tree builder that can be used for connecting task tree nodes
-     * @param nodeFactory the node factory that can be used for instantiating task tree nodes
      * 
      * @return the result of the merge or null if merging is not possible
      */
-    private ITaskTreeNode mergeEqualIterations(IIteration            iteration1,
-                                               IIteration            iteration2,
-                                               ITaskTreeBuilder      treeBuilder,
-                                               ITaskTreeNodeFactory  nodeFactory)
-    {
+    private ITaskTreeNode mergeEqualIterations(IIteration iteration1, IIteration iteration2) {
         ITaskTreeNode mergedChild = mergeEqualTasks
-            (iteration1.getChildren().get(0), iteration2.getChildren().get(0),
-             treeBuilder, nodeFactory);
+            (iteration1.getChildren().get(0), iteration2.getChildren().get(0));
         
         IIteration mergeResult = null;
         
         if (mergedChild != null) {
-            mergeResult = nodeFactory.createNewIteration();
-            treeBuilder.setChild(mergeResult, mergedChild);
+            mergeResult = taskTreeNodeFactory.createNewIteration();
+            taskTreeBuilder.setChild(mergeResult, mergedChild);
         }
         
@@ -598,15 +567,11 @@
      *
      * @param subsequences the identified and already merged equal subsequences
-     * @param treeBuilder  the tree builder that can be used for connecting task tree nodes
-     * @param nodeFactory  the node factory that can be used for instantiating the iteration
      * 
      * @return the resulting iteration
      */
     private IIteration createIterationBasedOnIdentifiedVariants(SubSequences          subsequences,
-                                                                ITaskTreeBuilder      treeBuilder,
-                                                                ITaskTreeNodeFactory  nodeFactory,
                                                                 RuleApplicationResult result)
     {
-        IIteration newIteration = nodeFactory.createNewIteration();
+        IIteration newIteration = taskTreeNodeFactory.createNewIteration();
         result.addNewlyCreatedParentNode(newIteration);
 
@@ -616,10 +581,10 @@
                 // there is only one equal variant and this has only one child. So create an
                 // iteration of this child
-                treeBuilder.setChild
+                taskTreeBuilder.setChild
                     (newIteration, subsequences.equalVariants.get(0).getChildren().get(0));
             }
             else {
                 // there was an iteration of one equal sequence
-                treeBuilder.setChild(newIteration, subsequences.equalVariants.get(0));
+                taskTreeBuilder.setChild(newIteration, subsequences.equalVariants.get(0));
                 result.addNewlyCreatedParentNode(subsequences.equalVariants.get(0));
             }
@@ -628,18 +593,18 @@
             // there are distinct variants of equal subsequences or children --> create an
             // iterated selection
-            ISelection selection = nodeFactory.createNewSelection();
+            ISelection selection = taskTreeNodeFactory.createNewSelection();
             result.addNewlyCreatedParentNode(selection);
 
             for (ITaskTreeNode variant : subsequences.equalVariants) {
                 if (variant.getChildren().size() == 1) {
-                    treeBuilder.addChild(selection, variant.getChildren().get(0));
+                    taskTreeBuilder.addChild(selection, variant.getChildren().get(0));
                 }
                 else {
-                    treeBuilder.addChild(selection, variant);
+                    taskTreeBuilder.addChild(selection, variant);
                     result.addNewlyCreatedParentNode(variant);
                 }
             }
 
-            treeBuilder.setChild(newIteration, selection);
+            taskTreeBuilder.setChild(newIteration, selection);
         }
         
Index: trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/temporalrelation/DefaultTaskSequenceDetectionRule.java
===================================================================
--- trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/temporalrelation/DefaultTaskSequenceDetectionRule.java	(revision 1107)
+++ trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/temporalrelation/DefaultTaskSequenceDetectionRule.java	(revision 1107)
@@ -0,0 +1,332 @@
+package de.ugoe.cs.autoquest.tasktrees.temporalrelation;
+
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+
+import de.ugoe.cs.autoquest.tasktrees.nodeequality.NodeEquality;
+import de.ugoe.cs.autoquest.tasktrees.nodeequality.NodeEqualityRuleManager;
+import de.ugoe.cs.autoquest.tasktrees.treeifc.ISequence;
+import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskTreeBuilder;
+import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskTreeNode;
+import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskTreeNodeFactory;
+import de.ugoe.cs.autoquest.usageprofiles.SymbolComparator;
+import de.ugoe.cs.autoquest.usageprofiles.Trie;
+
+/**
+ * <p>
+ * TODO comment
+ * </p>
+ * 
+ * @author Patrick Harms
+ */
+class DefaultTaskSequenceDetectionRule implements TemporalRelationshipRule {
+    
+    /**
+     * <p>
+     * the task tree node factory to be used for creating substructures for the temporal
+     * relationships identified during rule
+     * </p>
+     */
+    private ITaskTreeNodeFactory taskTreeNodeFactory;
+    /**
+     * <p>
+     * the task tree builder to be used for creating substructures for the temporal relationships
+     * identified during rule application
+     * </p>
+     */
+    private ITaskTreeBuilder taskTreeBuilder;
+
+    /**
+     * <p>
+     * the node comparator to be used for comparing task tree nodes
+     * </p>
+     */
+    private SymbolComparator<ITaskTreeNode> nodeComparator;
+
+    /**
+     * <p>
+     * instantiates the rule and initializes it with a node equality rule manager and the minimal
+     * node equality identified sublist must have to consider them as iterated.
+     * </p>
+     */
+    DefaultTaskSequenceDetectionRule(NodeEqualityRuleManager nodeEqualityRuleManager,
+                                     NodeEquality            minimalNodeEquality,
+                                     ITaskTreeNodeFactory    taskTreeNodeFactory,
+                                     ITaskTreeBuilder        taskTreeBuilder)
+    {
+        this.taskTreeNodeFactory = taskTreeNodeFactory;
+        this.taskTreeBuilder = taskTreeBuilder;
+        
+        this.nodeComparator =
+            new TaskTreeNodeComparator(nodeEqualityRuleManager, minimalNodeEquality);
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see de.ugoe.cs.tasktree.temporalrelation.TemporalRelationshipRule#apply(TaskTreeNode,
+     * boolean)
+     */
+    @Override
+    public RuleApplicationResult apply(ITaskTreeNode parent, boolean finalize) {
+        if (!(parent instanceof ISequence)) {
+            return null;
+        }
+
+        if (!finalize) {
+            // the rule is always feasible as tasks may occur at any time
+            RuleApplicationResult result = new RuleApplicationResult();
+            result.setRuleApplicationStatus(RuleApplicationStatus.RULE_APPLICATION_FEASIBLE);
+            return result;
+        }
+
+        long timestamp1;
+        long timestamp2 = System.currentTimeMillis();
+        long ms1 = 0;
+        long ms2 = 0;
+        long ms3 = 0;
+        long ms4 = 0;
+        
+        List<ISequence> createdSequences = new LinkedList<ISequence>();
+        
+        int evisagedNoOfOccurrences = 0;
+        
+        do {
+            timestamp1 = timestamp2;
+            Trie<ITaskTreeNode> trie = new Trie<ITaskTreeNode>(nodeComparator);
+        
+            System.out.println("training trie");
+            trainTrie(trie, parent, createdSequences);
+
+            timestamp2 = System.currentTimeMillis();
+            ms1 += timestamp2 - timestamp1;
+            timestamp1 = timestamp2;
+
+            System.out.println("determining most prominent tasks");
+            Collection<List<ITaskTreeNode>> tasks =
+                trie.getSequencesWithOccurrenceCount(2, evisagedNoOfOccurrences);
+            
+            tasks = sortAndRemovePermutationsOfShorterTasks(tasks); 
+        
+            timestamp2 = System.currentTimeMillis();
+            ms2 += timestamp2 - timestamp1;
+            timestamp1 = timestamp2;
+
+            if ((tasks != null) && (tasks.size() > 0)) {
+                Iterator<List<ITaskTreeNode>> tasksIterator = tasks.iterator();
+                
+                while (tasksIterator.hasNext()) {
+                    List<ITaskTreeNode> task = tasksIterator.next();
+                    evisagedNoOfOccurrences = trie.getCount(task);
+
+                    // only tasks occurring more often than once are of interest
+                    if (evisagedNoOfOccurrences > 1) {
+                        timestamp2 = System.currentTimeMillis();
+                        ms3 += timestamp2 - timestamp1;
+                        timestamp1 = timestamp2;
+
+                        String taskId = "task " + RuleUtils.getNewId();
+                        System.out.println("creating sequences for task " + taskId + ": " + task);
+                        createSequenceForTaskOccurrences(taskId, task, parent, createdSequences);
+
+                        timestamp2 = System.currentTimeMillis();
+                        ms4 += timestamp2 - timestamp1;
+                        timestamp1 = timestamp2;
+                    }
+                }
+            }
+            
+            evisagedNoOfOccurrences--;
+        }
+        while (evisagedNoOfOccurrences > 1);
+        
+        System.out.println(ms1 + "   " + ms2 + "   " + ms3 + "   " + ms4);
+        RuleApplicationResult result = new RuleApplicationResult();
+        
+        if (createdSequences.size() > 0) {
+            for (ISequence sequence : createdSequences) {
+                result.addNewlyCreatedParentNode(sequence);
+            }
+            
+            result.setRuleApplicationStatus(RuleApplicationStatus.RULE_APPLICATION_FINISHED);
+        }
+
+        
+        return result;
+    }
+
+    /**
+     * <p>
+     * TODO: comment
+     * </p>
+     *
+     * @param trie
+     * @param parent
+     */
+    private void trainTrie(Trie<ITaskTreeNode> trie,
+                           ITaskTreeNode       parent,
+                           List<ISequence>     createdSequences)
+    {
+        List<ITaskTreeNode> children = parent.getChildren();
+        
+        if ((children != null) && (children.size() > 0)) {
+            trie.train(children, children.size());
+            
+            for (ITaskTreeNode child : children) {
+                trainTrie(trie, child, createdSequences);
+            }
+        }
+    }
+
+    /**
+     *
+     */
+    private List<List<ITaskTreeNode>>
+        sortAndRemovePermutationsOfShorterTasks(Collection<List<ITaskTreeNode>> tasks)
+    {
+        // first of all create a sorted list of the tasks with the longest first
+        List<List<ITaskTreeNode>> sortedTasks = new LinkedList<List<ITaskTreeNode>>();
+        
+        boolean added;
+        for (List<ITaskTreeNode> task : tasks) {
+            added = false;
+            for (int i = 0; i < sortedTasks.size(); i++) {
+                if (sortedTasks.get(i).size() < task.size()) {
+                    sortedTasks.add(i, task);
+                    added = true;
+                    break;
+                }
+            }
+            
+            if (!added) {
+                sortedTasks.add(task);
+            }
+        }
+        
+        // now iterate the sorted list and for each task remove all other tasks that are shorter
+        // (i.e. come later in the sorted list) and that represent a subpart of the task
+        for (int i = 0; i < sortedTasks.size(); i++) {
+            for (int j = i + 1; j < sortedTasks.size();) {
+                if (sortedTasks.get(j).size() < sortedTasks.get(i).size()) {
+                    // found a task that is a potential subtask. Check for this and remove the
+                    // subtask if needed
+                    List<ITaskTreeNode> longTask = sortedTasks.get(i);
+                    List<ITaskTreeNode> shortTask = sortedTasks.get(j);
+                    
+                    if (getSubListIndex(longTask, shortTask, 0) > -1) {
+                        sortedTasks.remove(j);
+                    }
+                    else {
+                        j++;
+                    }
+                }
+                else {
+                    j++;
+                }
+            }
+        }
+        
+        return sortedTasks;
+    }
+
+    /**
+     * <p>
+     * TODO: comment
+     * </p>
+     *
+     * @param task
+     * @param parent
+     * @param treeBuilder
+     * @param nodeFactory
+     * @param result
+     */
+    private void createSequenceForTaskOccurrences(String              taskId,
+                                                  List<ITaskTreeNode> task,
+                                                  ITaskTreeNode       parent,
+                                                  List<ISequence>     createdSequences)
+    {
+        List<ITaskTreeNode> children = parent.getChildren();
+        
+        if ((children == null) || (children.size() == 0)) {
+            return;
+        }
+        
+        // first traverse the children
+        for (ITaskTreeNode child : children) {
+            createSequenceForTaskOccurrences(taskId, task, child, createdSequences);
+        }
+        
+        // now check the children themselves for an occurrence of the task
+        int index = -1;
+        
+        do {
+            index = getSubListIndex(children, task, ++index);
+            
+            if (index > -1) {
+                if (task.size() < children.size()) {
+                    ISequence sequence = RuleUtils.createNewSubSequenceInRange
+                        (parent, index, index + task.size() - 1, taskId,
+                         taskTreeNodeFactory, taskTreeBuilder);
+                    
+                    createdSequences.add(sequence);
+                 
+                    children = parent.getChildren();
+                }
+                else {
+                    // the whole list of children is an occurrence of this task. Just set the
+                    // description of the parent and break up
+                    String description = parent.getDescription();
+                    
+                    if ((description != null) && (description.length() > 0)) {
+                        description += "; " + taskId;
+                    }
+                    else {
+                        description = taskId;
+                    }
+                    
+                    taskTreeBuilder.setDescription(parent, description);
+                    break;
+                }
+            }
+        }
+        while (index > -1);
+    }
+
+    /**
+     * <p>
+     * TODO: comment
+     * </p>
+     *
+     * @param trie
+     * @param object
+     * @return
+     */
+    private int getSubListIndex(List<ITaskTreeNode> list,
+                                List<ITaskTreeNode> subList,
+                                int                 startIndex)
+    {
+        boolean matchFound;
+        int result = -1;
+        
+        for (int i = startIndex; i <= list.size() - subList.size(); i++) {
+            matchFound = true;
+            
+            for (int j = 0; j < subList.size(); j++) {
+                if (!nodeComparator.equals(list.get(i + j), subList.get(j))) {
+                    matchFound = false;
+                    break;
+                }
+            }
+            
+            if (matchFound) {
+                result = i;
+                break;
+            }
+        }
+        
+        return result;
+    }
+    
+}
Index: trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/temporalrelation/RuleUtils.java
===================================================================
--- trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/temporalrelation/RuleUtils.java	(revision 1107)
+++ trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/temporalrelation/RuleUtils.java	(revision 1107)
@@ -0,0 +1,73 @@
+//   Copyright 2012 Georg-August-Universität Göttingen, Germany
+//
+//   Licensed under the Apache License, Version 2.0 (the "License");
+//   you may not use this file except in compliance with the License.
+//   You may obtain a copy of the License at
+//
+//       http://www.apache.org/licenses/LICENSE-2.0
+//
+//   Unless required by applicable law or agreed to in writing, software
+//   distributed under the License is distributed on an "AS IS" BASIS,
+//   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+//   See the License for the specific language governing permissions and
+//   limitations under the License.
+
+package de.ugoe.cs.autoquest.tasktrees.temporalrelation;
+
+import de.ugoe.cs.autoquest.tasktrees.treeifc.ISequence;
+import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskTreeBuilder;
+import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskTreeNode;
+import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskTreeNodeFactory;
+
+/**
+ * <p>
+ * TODO comment
+ * </p>
+ * 
+ * @author Patrick Harms
+ */
+class RuleUtils {
+    
+    /** */
+    private static int idCounter = 0;
+
+    /**
+     * 
+     */
+    static ISequence createNewSubSequenceInRange(ITaskTreeNode         parent,
+                                                 int                   startIndex,
+                                                 int                   endIndex,
+                                                 String                description,
+                                                 ITaskTreeNodeFactory  nodeFactory,
+                                                 ITaskTreeBuilder      builder)
+    {
+        ISequence sequence = nodeFactory.createNewSequence();
+        if (description != null) {
+            builder.setDescription(sequence, description);
+        }
+
+        for (int i = startIndex; i <= endIndex; i++) {
+            builder.addChild(sequence, parent.getChildren().get(startIndex));
+            builder.removeChild((ISequence) parent, startIndex);
+        }
+
+        builder.addChild((ISequence) parent, startIndex, sequence);
+
+        return sequence;
+    }
+
+    /**
+     *
+     */
+    public static synchronized String getNewId() {
+        return Integer.toString(idCounter++);
+    }
+
+    /**
+     *
+     */
+    private RuleUtils() {
+        // prevent instantiation
+    }
+
+}
Index: trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/temporalrelation/TaskTreeNodeComparator.java
===================================================================
--- trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/temporalrelation/TaskTreeNodeComparator.java	(revision 1107)
+++ trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/temporalrelation/TaskTreeNodeComparator.java	(revision 1107)
@@ -0,0 +1,74 @@
+//   Copyright 2012 Georg-August-Universität Göttingen, Germany
+//
+//   Licensed under the Apache License, Version 2.0 (the "License");
+//   you may not use this file except in compliance with the License.
+//   You may obtain a copy of the License at
+//
+//       http://www.apache.org/licenses/LICENSE-2.0
+//
+//   Unless required by applicable law or agreed to in writing, software
+//   distributed under the License is distributed on an "AS IS" BASIS,
+//   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+//   See the License for the specific language governing permissions and
+//   limitations under the License.
+
+package de.ugoe.cs.autoquest.tasktrees.temporalrelation;
+
+import de.ugoe.cs.autoquest.tasktrees.nodeequality.NodeEquality;
+import de.ugoe.cs.autoquest.tasktrees.nodeequality.NodeEqualityRuleManager;
+import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskTreeNode;
+import de.ugoe.cs.autoquest.usageprofiles.SymbolComparator;
+
+/**
+ * <p>
+ * TODO comment
+ * </p>
+ * 
+ * @author Patrick Harms
+ */
+public class TaskTreeNodeComparator implements SymbolComparator<ITaskTreeNode> {
+    
+    /**
+     * <p>
+     * the node equality manager needed for comparing task tree nodes with each other
+     * </p>
+     */
+    private NodeEqualityRuleManager nodeEqualityRuleManager;
+
+    /**
+     * <p>
+     * the minimal node equality two identified sublists need to have to consider them as equal
+     * and to create an iteration for
+     * </p>
+     */
+    private NodeEquality minimalNodeEquality;
+
+
+
+    /**
+     * <p>
+     * TODO: comment
+     * </p>
+     *
+     * @param nodeEqualityRuleManager
+     * @param minimalNodeEquality
+     */
+    public TaskTreeNodeComparator(NodeEqualityRuleManager nodeEqualityRuleManager,
+                                  NodeEquality            minimalNodeEquality)
+    {
+        super();
+        this.nodeEqualityRuleManager = nodeEqualityRuleManager;
+        this.minimalNodeEquality = minimalNodeEquality;
+    }
+
+
+
+    /* (non-Javadoc)
+     * @see de.ugoe.cs.autoquest.tasktrees.temporalrelation.SymbolComparator#equals(java.lang.Object, java.lang.Object)
+     */
+    @Override
+    public boolean equals(ITaskTreeNode symbol1, ITaskTreeNode symbol2) {
+        return nodeEqualityRuleManager.applyRules(symbol1, symbol2).isAtLeast(minimalNodeEquality);
+    }
+
+}
Index: trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/temporalrelation/TemporalRelationshipRule.java
===================================================================
--- trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/temporalrelation/TemporalRelationshipRule.java	(revision 1099)
+++ trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/temporalrelation/TemporalRelationshipRule.java	(revision 1107)
@@ -1,14 +1,11 @@
 package de.ugoe.cs.autoquest.tasktrees.temporalrelation;
 
-import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskTreeBuilder;
 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskTreeNode;
-import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskTreeNodeFactory;
 
 /**
  * <p>
- * a temporal relation ship is able to detected temporal relationships between the child nodes
- * of the parent node provided to the
- * {@link #apply(ITaskTreeNode, ITaskTreeBuilder, ITaskTreeNodeFactory, boolean)} method. A rule
- * created temporal relationships between the child nodes, i.e. substructures in the task tree, if
+ * a temporal relationship rule is able to detected temporal relationships between the child nodes
+ * of the parent node provided to the {@link #apply(ITaskTreeNode, boolean)} method. A rule
+ * creates temporal relationships between the child nodes, i.e. substructures in the task tree, if
  * it detects a temporal relationship and it can be sure that it is complete. Incomplete but
  * detected temporal relationships may occur, if there can be more children expected to be added
@@ -23,8 +20,6 @@
   /**
    * <p>
-   * applies the rule to the given parent node. The provided builder and node factory are used
-   * to create substructures in the task tree for the identified temporal relationships. The
-   * finalize parameter is used to command the rule to finish rule applications, in the case it
-   * is known that no further data will be available. 
+   * applies the rule to the given parent node. The finalize parameter is used to command the rule
+   * to finish rule applications, in the case it is known that no further data will be available. 
    * </p>
    * <p>
@@ -38,18 +33,12 @@
    * </p>
    * 
-   * @param parent      the parent node with the children to apply the rule on
-   * @param builder     the builder to be used for creating substructures for the identified
-   *                    temporal relationships
-   * @param nodeFactory the node factory to be used for creating substructures for the identified
-   *                    temporal relationships
-   * @param finalize    true, if the rule shall not expect further children to come and that it
-   *                    should therefore be applied in any case
+   * @param parent   the parent node with the children to apply the rule on
+   * @param finalize true, if the rule shall not expect further children to come and that it
+   *                 should therefore be applied in any case
    *                    
    * @return the rule application result as described.
    */
-  RuleApplicationResult apply(ITaskTreeNode        parent,
-                              ITaskTreeBuilder     builder,
-                              ITaskTreeNodeFactory nodeFactory,
-                              boolean              finalize);
+  RuleApplicationResult apply(ITaskTreeNode parent,
+                              boolean       finalize);
   
 }
Index: trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/temporalrelation/TemporalRelationshipRuleManager.java
===================================================================
--- trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/temporalrelation/TemporalRelationshipRuleManager.java	(revision 1099)
+++ trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/temporalrelation/TemporalRelationshipRuleManager.java	(revision 1107)
@@ -79,19 +79,52 @@
     /**
      * <p>
-     * the temporal relationship rule known to the manager. The rules are applied in the order
-     * they occur in this list.
-     * </p>
-     */
-    private List<TemporalRelationshipRule> rules = new ArrayList<TemporalRelationshipRule>();
-
-    /**
-     * <p>
-     * initialize the manager with a node equality rule manager to be used by the known rules
-     * for task tree node comparison.
-     * </p>
-     */
-    public TemporalRelationshipRuleManager(NodeEqualityRuleManager nodeEqualityRuleManager) {
+     * the task tree node factory to be used during rule application
+     * </p>
+     */
+    private ITaskTreeNodeFactory taskTreeNodeFactory;
+
+    /**
+     * <p>
+     * the task tree builder to be used during rule application
+     * </p>
+     */
+    private ITaskTreeBuilder taskTreeBuilder;
+
+    /**
+     * <p>
+     * the temporal relationship rules known to the manager that are executed on whole sub trees.
+     * The rules are applied in the order they occur in this list.
+     * </p>
+     */
+    private TemporalRelationshipRule[] treeScopeRules;
+
+    /**
+     * <p>
+     * the temporal relationship rules known to the manager that are executed on whole sub trees.
+     * The rules are applied in the order they occur in this list.
+     * </p>
+     */
+    private TemporalRelationshipRule[] nodeScopeRules;
+
+    /**
+     * <p>
+     * initialize the manager
+     * </p>
+     * 
+     * @param nodeEqualityRuleManager the node equality rule manager to be used by the known rules
+     *                                for task tree node comparison during rule application
+     * @param taskTreeNodeFactory     the node factory to be used for instantiating new task tree
+     *                                nodes during rule application
+     * @param taskTreeBuilder         the task tree builder to be used for linking task tree nodes
+     *                                with each other during rule application
+     */
+    public TemporalRelationshipRuleManager(NodeEqualityRuleManager nodeEqualityRuleManager,
+                                           ITaskTreeNodeFactory    taskTreeNodeFactory,
+                                           ITaskTreeBuilder        taskTreeBuilder)
+    {
         super();
         this.nodeEqualityRuleManager = nodeEqualityRuleManager;
+        this.taskTreeNodeFactory = taskTreeNodeFactory;
+        this.taskTreeBuilder = taskTreeBuilder;
     }
 
@@ -107,17 +140,44 @@
         frameFilter.add(IFrame.class);
         frameFilter.add(IDialog.class);
-
-        rules.add(new DefaultGuiElementSequenceDetectionRule(frameFilter));
-        rules.add(new DefaultGuiElementSequenceDetectionRule());
-        rules.add(new DefaultEventTargetSequenceDetectionRule());
-        rules.add(new TrackBarSelectionDetectionRule(nodeEqualityRuleManager));
-        //rules.add(new DefaultGuiEventSequenceDetectionRule());
+        //frameFilter.add(ICanvas.class);
+
+        treeScopeRules = new TemporalRelationshipRule[] {
+            new DefaultTaskSequenceDetectionRule
+                (nodeEqualityRuleManager, NodeEquality.SEMANTICALLY_EQUAL,
+                 taskTreeNodeFactory, taskTreeBuilder)
+        };
         
-        rules.add(new DefaultIterationDetectionRule
-                      (nodeEqualityRuleManager, NodeEquality.LEXICALLY_EQUAL));
-        rules.add(new DefaultIterationDetectionRule
-                      (nodeEqualityRuleManager, NodeEquality.SYNTACTICALLY_EQUAL));
-        rules.add(new DefaultIterationDetectionRule
-                      (nodeEqualityRuleManager, NodeEquality.SEMANTICALLY_EQUAL));
+        //treeScopeRules.add(new DefaultGuiElementSequenceDetectionRule(frameFilter));
+
+        nodeScopeRules = new TemporalRelationshipRule[] {
+            //new DefaultGuiElementSequenceDetectionRule(taskTreeNodeFactory, taskTreeBuilder),
+            //new DefaultEventTargetSequenceDetectionRule(taskTreeNodeFactory, taskTreeBuilder),
+            new TrackBarSelectionDetectionRule
+                (nodeEqualityRuleManager, taskTreeNodeFactory, taskTreeBuilder),
+            //new DefaultGuiEventSequenceDetectionRule(taskTreeNodeFactory, taskTreeBuilder),
+            new DefaultIterationDetectionRule
+                (nodeEqualityRuleManager, NodeEquality.LEXICALLY_EQUAL,
+                 taskTreeNodeFactory, taskTreeBuilder),
+            new DefaultIterationDetectionRule
+                (nodeEqualityRuleManager, NodeEquality.SYNTACTICALLY_EQUAL,
+                 taskTreeNodeFactory, taskTreeBuilder),
+            new DefaultIterationDetectionRule
+                (nodeEqualityRuleManager, NodeEquality.SEMANTICALLY_EQUAL,
+                 taskTreeNodeFactory, taskTreeBuilder)
+        };
+
+    }
+
+    /**
+     * <p>
+     * applies the known rules to the provided parent node. For the creation of further nodes,
+     * the provided builder and node factory are utilized. The method expectes, that no more data
+     * is available and, therefore, finalizes the rule application.
+     * </p>
+     * 
+     * @param nodeFactory  the node factory to be used for instantiating new task tree nodes.
+     */
+    public void applyRules(ITaskTreeNode parent) {
+        applyRules(parent, true);
     }
 
@@ -132,16 +192,9 @@
      * 
      * @param parent       the parent node to apply the rules on
-     * @param builder      the task tree builder to be used for linking task tree nodes with each
-     *                     other
-     * @param nodeFactory  the node factory to be used for instantiating new task tree nodes.
      * @param finalize     used to indicate, if the rule application shall break up if a rule would
      *                     be feasible if further data was available, or not.
      */
-    public void applyRules(ITaskTreeNode        parent,
-                           ITaskTreeBuilder     builder,
-                           ITaskTreeNodeFactory nodeFactory,
-                           boolean              finalize)
-    {
-        applyRules(parent, builder, nodeFactory, finalize, "");
+    public void applyRules(ITaskTreeNode parent, boolean finalize) {
+        applyRules(treeScopeRules, parent, finalize, "");
     }
 
@@ -157,7 +210,4 @@
      * 
      * @param parent       the parent node to apply the rules on
-     * @param builder      the task tree builder to be used for linking task tree nodes with each
-     *                     other
-     * @param nodeFactory  the node factory to be used for instantiating new task tree nodes.
      * @param finalize     used to indicate, if the rule application shall break up if a rule would
      *                     be feasible if further data was available, or not.
@@ -165,9 +215,8 @@
      *                     on the recursion depth of calling this method.
      */
-    private int applyRules(ITaskTreeNode        parent,
-                           ITaskTreeBuilder     builder,
-                           ITaskTreeNodeFactory nodeFactory,
-                           boolean              finalize,
-                           String               logIndent)
+    private int applyRules(TemporalRelationshipRule[] rules,
+                           ITaskTreeNode              parent,
+                           boolean                    finalize,
+                           String                     logIndent)
     {
         Console.traceln(Level.FINER, logIndent + "applying rules for " + parent);
@@ -179,5 +228,5 @@
             do {
                 Console.traceln(Level.FINER, logIndent + "trying rule " + rule + " on " + parent);
-                result = rule.apply(parent, builder, nodeFactory, finalize);
+                result = rule.apply(parent, finalize);
 
                 if ((result != null) &&
@@ -193,5 +242,5 @@
                     for (ITaskTreeNode newParent : result.getNewlyCreatedParentNodes()) {
                         noOfRuleApplications +=
-                            applyRules(newParent, builder, nodeFactory, true, logIndent + "  ");
+                            applyRules(nodeScopeRules, newParent, true, logIndent + "  ");
                     }
                 }
Index: trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/temporalrelation/TrackBarSelectionDetectionRule.java
===================================================================
--- trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/temporalrelation/TrackBarSelectionDetectionRule.java	(revision 1099)
+++ trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/temporalrelation/TrackBarSelectionDetectionRule.java	(revision 1107)
@@ -19,15 +19,40 @@
  * @author 2012, last modified by $Author: patrick$
  */
-public class TrackBarSelectionDetectionRule implements TemporalRelationshipRule {
+class TrackBarSelectionDetectionRule implements TemporalRelationshipRule {
+    /**
+     * <p>
+     * the task tree node factory to be used for creating substructures for the temporal
+     * relationships identified during rule
+     * </p>
+     */
+    private ITaskTreeNodeFactory taskTreeNodeFactory;
+    /**
+     * <p>
+     * the task tree builder to be used for creating substructures for the temporal relationships
+     * identified during rule application
+     * </p>
+     */
+    private ITaskTreeBuilder taskTreeBuilder;
 
-    /** */
+    /**
+     * <p>
+     * the node equality manager needed for comparing task tree nodes with each other
+     * </p>
+     */
     private NodeEqualityRuleManager nodeEqualityRuleManager;
 
     /**
-     *
+     * <p>
+     * instantiates the rule and initializes it with a node equality rule manager and the minimal
+     * node equality identified sublist must have to consider them as iterated.
+     * </p>
      */
-    TrackBarSelectionDetectionRule(NodeEqualityRuleManager nodeEqualityRuleManager) {
-        super();
+    TrackBarSelectionDetectionRule(NodeEqualityRuleManager nodeEqualityRuleManager,
+                                   ITaskTreeNodeFactory    taskTreeNodeFactory,
+                                   ITaskTreeBuilder        taskTreeBuilder)
+    {
         this.nodeEqualityRuleManager = nodeEqualityRuleManager;
+        this.taskTreeNodeFactory = taskTreeNodeFactory;
+        this.taskTreeBuilder = taskTreeBuilder;
     }
 
@@ -35,12 +60,9 @@
      * (non-Javadoc)
      * 
-     * @see TemporalRelationshipRule#apply(TaskTreeNode, TaskTreeBuilder, TaskTreeNodeFactory)
+     * @see de.ugoe.cs.tasktree.temporalrelation.TemporalRelationshipRule#apply(TaskTreeNode,
+     * boolean)
      */
     @Override
-    public RuleApplicationResult apply(ITaskTreeNode        parent,
-                                       ITaskTreeBuilder     builder,
-                                       ITaskTreeNodeFactory nodeFactory,
-                                       boolean              finalize)
-    {
+    public RuleApplicationResult apply(ITaskTreeNode parent, boolean finalize) {
         if (!(parent instanceof ISequence)) {
             return null;
@@ -72,6 +94,6 @@
                 // Therefore,
                 // create an iteration with the different selectable values as selection children
-                handleValueSelections(parent, currentTrackBar, valueSelectionStartIndex, index - 1,
-                                      builder, nodeFactory, result);
+                handleValueSelections
+                    (parent, currentTrackBar, valueSelectionStartIndex, index - 1, result);
 
                 return result;
@@ -84,5 +106,5 @@
             if (finalize) {
                 handleValueSelections(parent, currentTrackBar, valueSelectionStartIndex,
-                                      parent.getChildren().size() - 1, builder, nodeFactory, result);
+                                      parent.getChildren().size() - 1, result);
             }
             else {
@@ -101,23 +123,21 @@
                                        int                   startIndex,
                                        int                   endIndex,
-                                       ITaskTreeBuilder      builder,
-                                       ITaskTreeNodeFactory  nodeFactory,
                                        RuleApplicationResult result)
     {
-        IIteration iteration = nodeFactory.createNewIteration();
-        builder.setDescription(iteration, "value selection on " + trackbar.getStringIdentifier());
+        IIteration iteration = taskTreeNodeFactory.createNewIteration();
+        taskTreeBuilder.setDescription
+            (iteration, "value selection on " + trackbar.getStringIdentifier());
         result.addNewlyCreatedParentNode(iteration);
 
-        ISelection selection = nodeFactory.createNewSelection();
+        ISelection selection = taskTreeNodeFactory.createNewSelection();
         result.addNewlyCreatedParentNode(selection);
-        builder.setChild(iteration, selection);
+        taskTreeBuilder.setChild(iteration, selection);
 
         for (int i = endIndex - startIndex; i >= 0; i--) {
-            addChildIfNecessary(selection, parent.getChildren().get(startIndex), builder,
-                                nodeFactory, result);
-            builder.removeChild((ISequence) parent, startIndex);
+            addChildIfNecessary(selection, parent.getChildren().get(startIndex), result);
+            taskTreeBuilder.removeChild((ISequence) parent, startIndex);
         }
 
-        builder.addChild((ISequence) parent, startIndex, iteration);
+        taskTreeBuilder.addChild((ISequence) parent, startIndex, iteration);
 
         result.setRuleApplicationStatus(RuleApplicationStatus.RULE_APPLICATION_FINISHED);
@@ -129,6 +149,4 @@
     private void addChildIfNecessary(ISelection            parentSelection,
                                      ITaskTreeNode         node,
-                                     ITaskTreeBuilder      builder,
-                                     ITaskTreeNodeFactory  nodeFactory,
                                      RuleApplicationResult result)
     {
@@ -144,5 +162,5 @@
 
         // if we did not return in the previous checks, then the node must be added
-        builder.addChild(parentSelection, node);
+        taskTreeBuilder.addChild(parentSelection, node);
     }
 
