Index: /trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/temporalrelation/SequenceForTaskDetectionRule.java
===================================================================
--- /trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/temporalrelation/SequenceForTaskDetectionRule.java	(revision 1336)
+++ /trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/temporalrelation/SequenceForTaskDetectionRule.java	(revision 1337)
@@ -112,5 +112,5 @@
     public RuleApplicationResult apply(List<IUserSession> sessions) {
         RuleApplicationData appData = new RuleApplicationData(sessions);
-
+        
         // this is the real rule application. Loop while something is replaced.
         harmonizeEventTaskInstancesModel(appData);
@@ -247,8 +247,10 @@
         }
         
-        IIterationInstance iterationInstance = null;
+        IIterationInstance iterationInstance;
         
         for (IUserSession session : sessions) {
             int index = 0;
+            iterationInstance = null;
+
             while (index < session.size()) {
                 // we prepared the task instances to refer to unique tasks, if they are treated
@@ -1026,3 +1028,68 @@
 
     }
+    
+    // methods for internal testing
+//    private void checkMatchingOfSessions(List<List<Event>>  flattenedSessions,
+//                                         List<IUserSession> sessions,
+//                                         String             when)
+//    {
+//        List<List<Event>> currentFlattenedSessions = flattenSessions(sessions);
+//        if (flattenedSessions.size() != currentFlattenedSessions.size()) {
+//            System.out.println("################## number of sessions changed after " + when);
+//        }
+//        else {
+//            for (int i = 0; i < flattenedSessions.size(); i++) {
+//                List<Event> expected = flattenedSessions.get(i);
+//                List<Event> current = currentFlattenedSessions.get(i);
+//            
+//                if (expected.size() != current.size()) {
+//                    System.out.println
+//                        ("################## length of session " + i + " changed after " + when);
+//                }
+//                else {
+//                    for (int j = 0; j < expected.size(); j++) {
+//                        if (!expected.get(j).equals(current.get(j))) {
+//                            System.out.println("################## event " + j + " of session " +
+//                                               i + " changed after " + when);
+//                        }
+//                    }
+//                }
+//            }     
+//        }
+//    }
+//
+//    private List<List<Event>> flattenSessions(List<IUserSession> sessions) {
+//        List<List<Event>> flattenedSessions = new ArrayList<List<Event>>();
+//        for (IUserSession session : sessions) {
+//            List<Event> flattenedUserSession = new ArrayList<Event>();
+//            flatten(session, flattenedUserSession);
+//            flattenedSessions.add(flattenedUserSession);
+//        }
+//
+//        return flattenedSessions;
+//    }
+//
+//    private void flatten(IUserSession iUserSession, List<Event> flattenedUserSession) {
+//        for (ITaskInstance instance : iUserSession) {
+//            flatten(instance, flattenedUserSession);
+//        }
+//    }
+//
+//    private void flatten(ITaskInstance instance, List<Event> flattenedUserSession) {
+//        if (instance instanceof ITaskInstanceList) {
+//            for (ITaskInstance child : (ITaskInstanceList) instance) {
+//                flatten(child, flattenedUserSession);
+//            }
+//        }
+//        else if (instance instanceof ISelectionInstance) {
+//            flatten(((ISelectionInstance) instance).getChild(), flattenedUserSession);
+//        }
+//        else if (instance instanceof IOptionalInstance) {
+//            flatten(((IOptionalInstance) instance).getChild(), flattenedUserSession);
+//        }
+//        else if (instance instanceof IEventTaskInstance) {
+//            flattenedUserSession.add(((IEventTaskInstance) instance).getEvent());
+//        }
+//    }
+
 }
