Index: branches/autoquest-core-tasktrees-alignment/src/main/java/de/ugoe/cs/autoquest/tasktrees/temporalrelation/SequenceForTaskDetectionRuleAlignment.java
===================================================================
--- branches/autoquest-core-tasktrees-alignment/src/main/java/de/ugoe/cs/autoquest/tasktrees/temporalrelation/SequenceForTaskDetectionRuleAlignment.java	(revision 1657)
+++ branches/autoquest-core-tasktrees-alignment/src/main/java/de/ugoe/cs/autoquest/tasktrees/temporalrelation/SequenceForTaskDetectionRuleAlignment.java	(revision 1662)
@@ -232,23 +232,5 @@
 			}
 		};
-		// Collections.sort(matchseqs, comparator);
-
-		// TODO: Harmonize matches: finding double matches and merge them
-		/*
-		 * Console.traceln(Level.INFO, "harmonizing matches"); int i=0;
-		 * 
-		 * while(i<matchseqs.size()) { int j=i; while(j<matchseqs.size()) {
-		 * if(i!=j) { if(matchseqs.get(i).equals(matchseqs.get(j))) {
-		 * //matchseqs.get(i).addOccurencesOf(matchseqs.get(j));
-		 * matchseqs.remove(j);
-		 * 
-		 * //System.out.println("Sequence " + i);
-		 * //matchseqs.get(i).getFirstSequence().printSequence();
-		 * //matchseqs.get(i).getSecondSequence().printSequence();
-		 * //System.out.println("is equal to sequence " + j);
-		 * //matchseqs.get(j).getFirstSequence().printSequence();
-		 * //matchseqs.get(j).getSecondSequence().printSequence(); continue; } }
-		 * j++; } i++; } Collections.sort(matchseqs, comparator);
-		 */
+		Collections.sort(matchseqs, comparator);
 
 		HashMap<Integer, List<MatchOccurence>> replacedOccurences = new HashMap<Integer, List<MatchOccurence>>();
@@ -277,67 +259,25 @@
 					System.out.println();
 
-					//System.out.println("Printing session: ");
+					// System.out.println("Printing session: ");
 					for (int j = 0; j < sessions.get(oc.getSequenceId()).size(); j++) {
-					  System.out.println(j + ": "+ sessions.get(oc.getSequenceId()).get(j));
+						System.out.println(j + ": "
+								+ sessions.get(oc.getSequenceId()).get(j));
 					}
 
-					// Check if nothing has been replaced in the sequence we
-					// want to replace
-					if (replacedOccurences.get(oc.getSequenceId()) == null) {
-						replacedOccurences.put(oc.getSequenceId(),
-								new LinkedList<MatchOccurence>());
-					} else {
-						// check if we have any replaced occurence with indexes
-						// smaller than ours. If so, we need to adjust our start
-						// and endpoints
-						// of the replacement.
-						// Also do a check if we have replaced this specific
-						// MatchOccurence in this sequence already. Jump to the
-						// next occurence if this is the case.
-						// This is no more neccessary once the matches are
-						// harmonized.
-						for (Iterator<MatchOccurence> jt = replacedOccurences
-								.get(oc.getSequenceId()).iterator(); jt
-								.hasNext();) {
-							MatchOccurence tmpOC = jt.next();
-							if (tmpOC.getStartindex() == oc.getStartindex()) {
-								System.out.println("This position has already been replaced in this iteration");
-								continue invalidOccurence;
-								
-							}
-							if (tmpOC.getStartindex() < oc
-									.getStartindex()) {
-								int diff = tmpOC.getEndindex()
-										- tmpOC.getStartindex();
-								// Just to be sure.
-								if (diff > 0) {
-									System.out.println("Old index: Start: "
-											+ oc.getStartindex() + " End "
-											+ oc.getEndindex());
-									oc.setStartindex(oc.getStartindex() - diff+1);
-									oc.setEndindex(oc.getEndindex() - diff+1);
-									System.out.println("Updated index: Start: "
-											+ oc.getStartindex() + " End "
-											+ oc.getEndindex());
-								} else {
-									Console.traceln(Level.WARNING,
-											"End index of a Match before start. This should never happen");
-								}
-							}
-						}
-					}
-
-					
-					ISequenceInstance sequenceInstances = RuleUtils.createNewSubSequenceInRange(
-							sessions.get(oc.getSequenceId()),
-							oc.getStartindex(), oc.getEndindex(), task,
-							taskFactory, taskBuilder);
-					
-					//Adjust the length of the match regarding to the length of instance. (OptionalInstances may be shorter) 
-					oc.setEndindex(oc.getStartindex()+sequenceInstances.size()-RuleUtils.missedOptionals);
-					replacedOccurences.get(oc.getSequenceId()).add(oc);
-				}
-			
-				System.out.println();
+					ISequenceInstance sequenceInstances = RuleUtils
+							.createNewSubSequenceInRange(
+									sessions.get(oc.getSequenceId()),
+									oc.getStartindex(), oc.getEndindex(), task,
+									taskFactory, taskBuilder);
+					// Adjust the length of the match regarding to the length of
+					// instance. (OptionalInstances may be shorter)
+					oc.setEndindex(oc.getStartindex()
+							+ sequenceInstances.size()
+							- RuleUtils.missedOptionals);
+
+					updateMatchIndexes(matchseqs, oc.getSequenceId(),
+							oc.getStartindex(), oc.getEndindex());
+
+				}
 			}
 		}
@@ -373,4 +313,44 @@
 
 		return appData.getResult();
+	}
+
+	// check if we have any replaced occurence with indexes
+	// smaller than ours. If so, we need to adjust our start
+	// and endpoints
+	// of the replacement.
+	// Also do a check if we have replaced this specific
+	// MatchOccurence in this sequence already. Jump to the
+	// next occurence if this is the case.
+	private void updateMatchIndexes(List<Match> matchseqs, int sequenceId,
+			int startindex, int endindex) {
+
+		for (int i = 0; i < matchseqs.size(); i++) {
+			for (Iterator<MatchOccurence> it = matchseqs.get(i).getOccurences()
+					.iterator(); it.hasNext();) {
+				MatchOccurence tmpOC = it.next();
+				// if the matchoccurence starts in a sequence that has been
+				// replaced right now we delete it
+				if (tmpOC.getStartindex() > startindex
+						&& tmpOC.getStartindex() < endindex) {
+					it.remove();
+				} else if (tmpOC.getStartindex() > endindex) {
+					int diff =  endindex-startindex;
+					// Just to be sure.
+					if (diff > 0) {
+						System.out.println("Old index: Start: "
+								+ tmpOC.getStartindex() + " End "
+								+ tmpOC.getEndindex());
+						tmpOC.setStartindex(tmpOC.getStartindex() - diff + 1);
+						tmpOC.setEndindex(tmpOC.getEndindex() - diff + 1);
+						System.out.println("Updated index: Start: "
+								+ tmpOC.getStartindex() + " End "
+								+ tmpOC.getEndindex());
+					} else {
+						Console.traceln(Level.WARNING,
+								"End index of a Match before start. This should never happen");
+					}
+				}
+			}
+		}
 	}
 
@@ -422,11 +402,11 @@
 				appData.getNumber2Task().put(templist.getSequence()[i],
 						taskInstance.getTask());
-				
-				//if(j==1) {
-				//	System.out.println(i + ": TaskID: " +
-				//	taskInstance.getTask().getId()+ " Numbersequence: " +
-				//	templist.getSequence()[i]);
-				//}
-				
+
+				// if(j==1) {
+				// System.out.println(i + ": TaskID: " +
+				// taskInstance.getTask().getId()+ " Numbersequence: " +
+				// templist.getSequence()[i]);
+				// }
+
 			}
 			// Each NumberSequence is identified by its id, beginning to count
