diff --git a/alib2algo/src/tree/properties/BadCharacterShiftTable.h b/alib2algo/src/tree/properties/BadCharacterShiftTable.h
index d7b31da7641518da62bb43b3353009c009e58b06..388f8b91e74658c53af13317c0688c2351bff6c0 100644
--- a/alib2algo/src/tree/properties/BadCharacterShiftTable.h
+++ b/alib2algo/src/tree/properties/BadCharacterShiftTable.h
@@ -12,6 +12,8 @@
 #include <tree/ranked/PrefixRankedBarPattern.h>
 #include <tree/ranked/PrefixRankedBarNonlinearPattern.h>
 
+#include "LastVariableOffsetBack.h"
+
 #include <alib/set>
 #include <alib/map>
 
@@ -53,11 +55,7 @@ ext::map < common::ranked_symbol < SymbolType, RankType >, size_t > BadCharacter
 
 	 // find the distance between the end of the pattern and the index
 	 // of the last symbol representing the variable
-	unsigned lastSOffset = pattern.getContent ( ).size ( );
-
-	for ( unsigned i = 0; i < pattern.getContent ( ).size ( ); i++ )
-		if ( pattern.getContent ( )[i] == pattern.getSubtreeWildcard ( ) || pattern.getNonlinearVariables ( ).count ( pattern.getContent ( )[i] ) )
-			lastSOffset = pattern.getContent ( ).size ( ) - i - 1;
+	size_t lastSOffset = LastVariableOffsetBack::offset ( pattern );
 
 	// limit the shift by occurrence of the last variable
 
diff --git a/alib2algo/src/tree/properties/FirstVariableOffsetFront.h b/alib2algo/src/tree/properties/FirstVariableOffsetFront.h
new file mode 100644
index 0000000000000000000000000000000000000000..ccd90eacbdf2076e9c8978fe024df095596b3238
--- /dev/null
+++ b/alib2algo/src/tree/properties/FirstVariableOffsetFront.h
@@ -0,0 +1,49 @@
+/*
+ * FirstVariableOffsetFront.h
+ *
+ *  Created on: 5. 11. 2014
+ *      Author: Jan Travnicek
+ */
+
+#ifndef _FIRST_VARIABLE_OFFSET_FRONT_H_
+#define _FIRST_VARIABLE_OFFSET_FRONT_H_
+
+#include <tree/ranked/PrefixRankedPattern.h>
+#include <tree/ranked/PrefixRankedNonlinearPattern.h>
+
+namespace tree {
+
+namespace properties {
+
+class FirstVariableOffsetFront {
+public:
+	template < class SymbolType, class RankType >
+	static size_t offset ( const tree::PrefixRankedPattern < SymbolType, RankType > & pattern );
+	template < class SymbolType, class RankType >
+	static size_t offset ( const tree::PrefixRankedNonlinearPattern < SymbolType, RankType > & pattern );
+
+};
+
+template < class SymbolType, class RankType >
+size_t FirstVariableOffsetFront::offset ( const tree::PrefixRankedPattern < SymbolType, RankType > & pattern ) {
+	return offset ( tree::PrefixRankedNonlinearPattern < SymbolType, RankType > ( pattern ) );
+}
+
+template < class SymbolType, class RankType >
+size_t FirstVariableOffsetFront::offset ( const tree::PrefixRankedNonlinearPattern < SymbolType, RankType > & pattern ) {
+	 // find the distance between the beginning of the pattern and the index
+	 // of the first symbol representing the variable's bar
+	size_t res = pattern.getContent ( ).size ( ) + 1;
+
+	for ( int i = ( int ) pattern.getContent ( ).size ( ) - 1; i >= 0; i-- )
+		if ( pattern.getContent ( )[i] == pattern.getSubtreeWildcard ( ) || pattern.getNonlinearVariables ( ).count ( pattern.getContent ( )[i] ) )
+			res = i;
+
+	return res;
+}
+
+} /* namespace properties */
+
+} /* namespace tree */
+
+#endif /* _FIRST_VARIABLES_OFFSET_FRONT_H_ */
diff --git a/alib2algo/src/tree/properties/FirstVariablesBarOffsetFront.h b/alib2algo/src/tree/properties/FirstVariablesBarOffsetFront.h
new file mode 100644
index 0000000000000000000000000000000000000000..f5577a1aa3795aa4099b5ed3ded61f6dccf7c68a
--- /dev/null
+++ b/alib2algo/src/tree/properties/FirstVariablesBarOffsetFront.h
@@ -0,0 +1,49 @@
+/*
+ * FirstVariablesBarOffsetFront.h
+ *
+ *  Created on: 5. 11. 2014
+ *      Author: Jan Travnicek
+ */
+
+#ifndef _FIRST_VARIABLES_BAR_OFFSET_FRONT_H_
+#define _FIRST_VARIABLES_BAR_OFFSET_FRONT_H_
+
+#include <tree/ranked/PrefixRankedBarPattern.h>
+#include <tree/ranked/PrefixRankedBarNonlinearPattern.h>
+
+namespace tree {
+
+namespace properties {
+
+class FirstVariablesBarOffsetFront {
+public:
+	template < class SymbolType, class RankType >
+	static size_t offset ( const tree::PrefixRankedBarPattern < SymbolType, RankType > & pattern );
+	template < class SymbolType, class RankType >
+	static size_t offset ( const tree::PrefixRankedBarNonlinearPattern < SymbolType, RankType > & pattern );
+
+};
+
+template < class SymbolType, class RankType >
+size_t FirstVariablesBarOffsetFront::offset ( const tree::PrefixRankedBarPattern < SymbolType, RankType > & pattern ) {
+	return offset ( tree::PrefixRankedBarNonlinearPattern < SymbolType, RankType > ( pattern ) );
+}
+
+template < class SymbolType, class RankType >
+size_t FirstVariablesBarOffsetFront::offset ( const tree::PrefixRankedBarNonlinearPattern < SymbolType, RankType > & pattern ) {
+	 // find the distance between the beginning of the pattern and the index
+	 // of the first symbol representing the variable's bar
+	size_t res = pattern.getContent ( ).size ( ) + 1;
+
+	for ( int i = ( int ) pattern.getContent ( ).size ( ) - 1; i >= 0; i-- )
+		if ( pattern.getContent ( )[i] == pattern.getVariablesBar ( ) )
+			res = i;
+
+	return res;
+}
+
+} /* namespace properties */
+
+} /* namespace tree */
+
+#endif /* _FIRST_VARIABLES_BAR_OFFSET_FRONT_H_ */
diff --git a/alib2algo/src/tree/properties/LastVariableOffsetBack.h b/alib2algo/src/tree/properties/LastVariableOffsetBack.h
new file mode 100644
index 0000000000000000000000000000000000000000..a498c3d37d8e90b7a321afc464d21db653d2ec4b
--- /dev/null
+++ b/alib2algo/src/tree/properties/LastVariableOffsetBack.h
@@ -0,0 +1,50 @@
+/*
+ * LastVariableOffsetBack.h
+ *
+ *  Created on: 2. 4. 2018
+ *      Author: Jan Travnicek
+ */
+
+#ifndef _LAST_VARIABLE_OFFSET_BACK_H_
+#define _LAST_VARIABLE_OFFSET_BACK_H_
+
+#include <alphabet/RankedSymbol.h>
+#include <tree/ranked/PrefixRankedBarPattern.h>
+#include <tree/ranked/PrefixRankedBarNonlinearPattern.h>
+
+namespace tree {
+
+namespace properties {
+
+class LastVariableOffsetBack {
+public:
+	template < class SymbolType, class RankType >
+	static size_t offset ( const tree::PrefixRankedBarPattern < SymbolType, RankType > & pattern );
+	template < class SymbolType, class RankType >
+	static size_t offset ( const tree::PrefixRankedBarNonlinearPattern < SymbolType, RankType > & pattern );
+
+};
+
+template < class SymbolType, class RankType >
+size_t LastVariableOffsetBack::offset ( const tree::PrefixRankedBarPattern < SymbolType, RankType > & pattern ) {
+	return offset ( tree::PrefixRankedBarNonlinearPattern < SymbolType, RankType > ( pattern ) );
+}
+
+template < class SymbolType, class RankType >
+size_t LastVariableOffsetBack::offset ( const tree::PrefixRankedBarNonlinearPattern < SymbolType, RankType > & pattern ) {
+	 // find the distance between the end of the pattern and the index
+	 // of the last symbol representing the variable
+	size_t offset = pattern.getContent ( ).size ( );
+
+	for ( size_t i = 0; i < pattern.getContent ( ).size ( ); i++ )
+		if ( pattern.getContent ( )[i] == pattern.getSubtreeWildcard ( ) || pattern.getNonlinearVariables ( ).count ( pattern.getContent ( )[i] ) )
+			offset = pattern.getContent ( ).size ( ) - i - 1;
+
+	return offset;
+}
+
+} /* namespace properties */
+
+} /* namespace tree */
+
+#endif /* _LAST_VARIABLE_OFFSET_BACK_H_ */
diff --git a/alib2algo/src/tree/properties/ReversedBadCharacterShiftTable.h b/alib2algo/src/tree/properties/ReversedBadCharacterShiftTable.h
index df7d3aff10234dd95a0c41841f7b17bb34a63d27..9f3978967aba61c3581fcd9afd31ad824c9bbbc5 100644
--- a/alib2algo/src/tree/properties/ReversedBadCharacterShiftTable.h
+++ b/alib2algo/src/tree/properties/ReversedBadCharacterShiftTable.h
@@ -16,6 +16,9 @@
 #include <tree/ranked/PrefixRankedPattern.h>
 #include <tree/ranked/PrefixRankedNonlinearPattern.h>
 
+#include "FirstVariablesBarOffsetFront.h"
+#include "FirstVariableOffsetFront.h"
+
 namespace tree {
 
 namespace properties {
@@ -61,11 +64,7 @@ ext::map < common::ranked_symbol < SymbolType, RankType >, size_t > ReversedBadC
 
 	 // find the distance between the beginning of the pattern and the index
 	 // of the first symbol representing the variable's bar
-	unsigned firstSBarOffset = pattern.getContent ( ).size ( ) + 1;
-
-	for ( int i = ( int ) pattern.getContent ( ).size ( ) - 1; i >= 0; i-- )
-		if ( pattern.getContent ( )[i] == pattern.getVariablesBar ( ) )
-			firstSBarOffset = i;
+	size_t firstSBarOffset = FirstVariablesBarOffsetFront::offset ( pattern );
 
 	// limit the shift by occurrence of the last variable
 
@@ -121,11 +120,7 @@ ext::map < common::ranked_symbol < SymbolType, RankType >, size_t > ReversedBadC
 
 	 // find the distance between the beginning of the pattern and the index
 	 // of the first symbol representing the variable's bar
-	unsigned firstSOffset = pattern.getContent ( ).size ( ) + 1;
-
-	for ( int i = ( int ) pattern.getContent ( ).size ( ) - 1; i >= 0; i-- )
-		if ( pattern.getContent ( )[i] == pattern.getSubtreeWildcard ( ) || pattern.getNonlinearVariables ( ).count ( pattern.getContent ( )[i] ) )
-			firstSOffset = i;
+	size_t firstSOffset = FirstVariableOffsetFront::offset ( pattern );
 
 	if ( firstSOffset == 0 ) firstSOffset = 1;