diff --git a/alib2algo/src/stringology/query/SuffixArrayFactors.h b/alib2algo/src/stringology/query/SuffixArrayFactors.h
index 9187fd5e26e4eb20863aaf99854cfdf5d86ddb2b..8724b0306a479ba5737781fcf0e1b8f8bdf59df9 100644
--- a/alib2algo/src/stringology/query/SuffixArrayFactors.h
+++ b/alib2algo/src/stringology/query/SuffixArrayFactors.h
@@ -43,7 +43,7 @@ public:
 template < class SymbolType >
 std::set < unsigned > SuffixArrayFactors::query ( const indexes::SuffixArray < SymbolType > & suffixArray, const string::LinearString < SymbolType > & string ) {
 
-	auto comparator = [ & ] ( const std::vector < SymbolType > & first, unsigned firstIndex, const std::vector < SymbolType > & second, unsigned secondIndex, unsigned limit ) {
+	auto comparator = [ & ] ( const std::vector < SymbolType > & first, unsigned firstIndex, const std::vector < SymbolType > & second, unsigned secondIndex, unsigned limit ) -> int {
 			static std::compare < SymbolType > comp;
 
 			for ( ; firstIndex < first.size ( ) && secondIndex < second.size ( ) && limit > 0; ++ firstIndex, ++ secondIndex, --limit ) {
@@ -56,16 +56,7 @@ std::set < unsigned > SuffixArrayFactors::query ( const indexes::SuffixArray < S
 			if ( limit == 0 )
 				return 0;
 
-			if ( first.size ( ) == firstIndex && second.size ( ) == secondIndex )
-				return 0;
-
-			if ( first.size ( ) == firstIndex )
-				return -1;
-
-			if ( second.size ( ) == secondIndex )
-				return 1;
-
-			return 0;
+			return ( first.size ( ) - firstIndex ) - ( second.size ( ) - secondIndex );
 	};
 
 	// The value returned by comparator indicates whether the first argument is considered to go before the second.