diff --git a/alib2algo/src/arbology/exact/ReversedBoyerMooreHorspool.h b/alib2algo/src/arbology/exact/ReversedBoyerMooreHorspool.h
index 626cc889b596b5d8ce24ae66756ffbdc5aed001a..d5031de94722e1f26c378167a9c7296163558a95 100644
--- a/alib2algo/src/arbology/exact/ReversedBoyerMooreHorspool.h
+++ b/alib2algo/src/arbology/exact/ReversedBoyerMooreHorspool.h
@@ -65,7 +65,7 @@ ext::set < unsigned > ReversedBoyerMooreHorspool::match ( const tree::PrefixRank
 	ext::vector < int > subjectSubtreeJumpTable = tree::properties::SubtreeJumpTable::compute ( subject );
 
 	 // index to the subject
-	int i = ( int ) subject.getContent ( ).size ( ) - pattern.getContent ( ).size ( ) + 1;
+	int i = ( int ) subject.getContent ( ).size ( ) - pattern.getContent ( ).size ( );
 
 	 // main loop of the algorithm over all possible indexes where the pattern can start
 	while ( i >= 0 ) {
@@ -92,7 +92,7 @@ ext::set < unsigned > ReversedBoyerMooreHorspool::match ( const tree::PrefixRank
 	tree::PrefixRankedBarTree < unsigned, RankType > repeats = tree::properties::ExactSubtreeRepeatsNaive::repeats ( subject );
 
 	 // index to the subject
-	int i = ( int ) subject.getContent ( ).size ( ) - pattern.getContent ( ).size ( ) + 1;
+	int i = ( int ) subject.getContent ( ).size ( ) - pattern.getContent ( ).size ( );
 
 	 // main loop of the algorithm over all possible indexes where the pattern can start
 	while ( i >= 0 ) {
@@ -121,7 +121,7 @@ ext::set < unsigned > ReversedBoyerMooreHorspool::match ( const tree::PrefixRank
 	ext::vector < int > subjectSubtreeJumpTable = tree::properties::SubtreeJumpTable::compute ( subject );
 
 	 // index to the subject
-	int i = ( int ) subject.getContent ( ).size ( ) - pattern.getContent ( ).size ( ) + 1;
+	int i = ( int ) subject.getContent ( ).size ( ) - pattern.getContent ( ).size ( );
 
 	 // main loop of the algorithm over all possible indexes where the pattern can start
 	while ( i >= 0 ) {
@@ -148,7 +148,7 @@ ext::set < unsigned > ReversedBoyerMooreHorspool::match ( const tree::PrefixRank
 	tree::PrefixRankedTree < unsigned, RankType > repeats = tree::properties::ExactSubtreeRepeatsNaive::repeats ( subject );
 
 	 // index to the subject
-	int i = ( int ) subject.getContent ( ).size ( ) - pattern.getContent ( ).size ( ) + 1;
+	int i = ( int ) subject.getContent ( ).size ( ) - pattern.getContent ( ).size ( );
 
 	 // main loop of the algorithm over all possible indexes where the pattern can start
 	while ( i >= 0 ) {
diff --git a/alib2algo/src/arbology/exact/ReversedQuickSearch.h b/alib2algo/src/arbology/exact/ReversedQuickSearch.h
index 8fdd64a459bc31cd65b24d522c97655b0be1dc55..55452941a71bdefb519648cd1596077377363550 100644
--- a/alib2algo/src/arbology/exact/ReversedQuickSearch.h
+++ b/alib2algo/src/arbology/exact/ReversedQuickSearch.h
@@ -66,7 +66,7 @@ ext::set < unsigned > ReversedQuickSearch::match ( const tree::PrefixRankedBarTr
 	ext::vector < int > subjectSubtreeJumpTable = tree::properties::SubtreeJumpTable::compute ( subject );
 
 	// index to the subject
-	int i = ( int ) subject.getContent ( ).size ( ) - pattern.getContent ( ).size ( ) + 1;
+	int i = ( int ) subject.getContent ( ).size ( ) - pattern.getContent ( ).size ( );
 
 	// main loop of the algorithm over all possible indexes where the pattern can start
 	while ( i >= 0 ) {
@@ -100,7 +100,7 @@ ext::set < unsigned > ReversedQuickSearch::match ( const tree::PrefixRankedBarTr
 	tree::PrefixRankedBarTree < unsigned, RankType > repeats = tree::properties::ExactSubtreeRepeatsNaive::repeats ( subject );
 
 	// index to the subject
-	int i = ( int ) subject.getContent ( ).size ( ) - pattern.getContent ( ).size ( ) + 1;
+	int i = ( int ) subject.getContent ( ).size ( ) - pattern.getContent ( ).size ( );
 
 	// main loop of the algorithm over all possible indexes where the pattern can start
 	while ( i >= 0 ) {
@@ -135,7 +135,7 @@ ext::set < unsigned > ReversedQuickSearch::match ( const tree::PrefixRankedTree
 	ext::vector < int > subjectSubtreeJumpTable = tree::properties::SubtreeJumpTable::compute ( subject );
 
 	// index to the subject
-	int i = ( int ) subject.getContent ( ).size ( ) - pattern.getContent ( ).size ( ) + 1;
+	int i = ( int ) subject.getContent ( ).size ( ) - pattern.getContent ( ).size ( );
 
 	// main loop of the algorithm over all possible indexes where the pattern can start
 	while ( i >= 0 ) {
@@ -166,7 +166,7 @@ ext::set < unsigned > ReversedQuickSearch::match ( const tree::PrefixRankedTree
 	tree::PrefixRankedTree < unsigned, RankType > repeats = tree::properties::ExactSubtreeRepeatsNaive::repeats ( subject );
 
 	// index to the subject
-	int i = ( int ) subject.getContent ( ).size ( ) - pattern.getContent ( ).size ( ) + 1;
+	int i = ( int ) subject.getContent ( ).size ( ) - pattern.getContent ( ).size ( );
 
 	// main loop of the algorithm over all possible indexes where the pattern can start
 	while ( i >= 0 ) {
diff --git a/alib2algo/src/tree/exact/BackwardOccurrenceTest.h b/alib2algo/src/tree/exact/BackwardOccurrenceTest.h
index 3a0e46afa56b37378318fde95850ea433e740c27..87bba3186999e5466e22435c6cb1e3c9b1e19bc4 100644
--- a/alib2algo/src/tree/exact/BackwardOccurrenceTest.h
+++ b/alib2algo/src/tree/exact/BackwardOccurrenceTest.h
@@ -50,7 +50,7 @@ ext::pair < int, int > BackwardOccurrenceTest::occurrence ( const PrefixRankedBa
 			 // match of symbol
 			offset = offset - 1;
 			j = j - 1;
-		} else if ( ( pattern.getContent ( )[j] == pattern.getVariablesBar ( ) ) /* && ( pattern.getBars ( ).count ( subject.getContent ( )[offset] ) ) */ ) {
+		} else if ( ( pattern.getContent ( )[j] == pattern.getVariablesBar ( ) ) && ( subject.getBars ( ).count ( subject.getContent ( )[offset] ) ) ) { //the second part of the condition is needed to handle S |S
 			 // match of variable with subtree
 			offset = subjectSubtreeJumpTable[offset];
 			j = j - 2;
@@ -79,7 +79,7 @@ ext::pair < int, int > BackwardOccurrenceTest::occurrence ( const PrefixRankedBa
 			 // match of symbol
 			offset = offset - 1;
 			j = j - 1;
-		} else if ( ( pattern.getContent ( )[j] == pattern.getVariablesBar ( ) ) /* && ( pattern.getBars ( ).count ( subject.getContent ( )[offset] ) ) */ ) {
+		} else if ( ( pattern.getContent ( )[j] == pattern.getVariablesBar ( ) ) && ( subject.getBars ( ).count ( subject.getContent ( )[offset] ) ) ) { //the second part of the condition is needed to handle S |S
 			 // else match of variable with subtree
 			offset = subjectSubtreeJumpTable[offset];
 			j = j - 2;
diff --git a/alib2algo/src/tree/exact/ForwardOccurrenceTest.h b/alib2algo/src/tree/exact/ForwardOccurrenceTest.h
index cf97699cc1b7a1261ad2ae87779346bc19126115..62dd723c88ec3084e553fd216ea3a234029be32e 100644
--- a/alib2algo/src/tree/exact/ForwardOccurrenceTest.h
+++ b/alib2algo/src/tree/exact/ForwardOccurrenceTest.h
@@ -54,7 +54,7 @@ size_t ForwardOccurrenceTest::occurrence ( const PrefixRankedBarTree < SymbolTyp
 			 // match of symbol
 			offset = offset + 1;
 			j = j + 1;
-		} else if ( ( pattern.getContent ( )[j] == pattern.getSubtreeWildcard ( ) ) /* && ( ! pattern.getBars ( ).count ( subject.getContent ( )[offset] ) ) */ ) {
+		} else if ( ( pattern.getContent ( )[j] == pattern.getSubtreeWildcard ( ) ) && ( ! subject.getBars ( ).count ( subject.getContent ( )[offset] ) ) ) { //the second part of the condition is needed to handle S |S
 			 // match of variable with subtree
 			offset = subjectSubtreeJumpTable[offset];
 			j = j + 2;
@@ -81,7 +81,7 @@ size_t ForwardOccurrenceTest::occurrence ( const PrefixRankedBarTree < SymbolTyp
 			 // match of symbol
 			offset = offset + 1;
 			j = j + 1;
-		} else if ( ( pattern.getContent ( )[j] == pattern.getSubtreeWildcard ( ) || pattern.getNonlinearVariables ( ).count ( pattern.getContent ( )[j] ) ) /* && ( ! pattern.getBars ( ).count ( subject.getContent ( )[offset] ) ) */ ) {
+		} else if ( ( pattern.getContent ( )[j] == pattern.getSubtreeWildcard ( ) || pattern.getNonlinearVariables ( ).count ( pattern.getContent ( )[j] ) ) && ( ! subject.getBars ( ).count ( subject.getContent ( )[offset] ) ) ) { //the second part of the condition is needed to handle S |S
 			 // check nonlinear variable
 			if ( pattern.getNonlinearVariables ( ).count ( pattern.getContent ( )[ j ] ) ) {
 				auto setting = variablesSetting.find ( pattern.getContent ( )[ j ] );