diff --git a/jars/similarityoperators.jar b/jars/similarityoperators.jar
index fde259d77bad5c2e611aa6b4b0c6d12664b2fa37..622450a9af5c7fea1d438b1ff2045ba29742a310 100644
Binary files a/jars/similarityoperators.jar and b/jars/similarityoperators.jar differ
diff --git a/src/mhtree/MHTree.java b/src/mhtree/MHTree.java
index 23df786fd416560e3861ed67539af587f4c4cab9..fb71ff51bf0a9e87376f225d2c67e97a79dd07c8 100644
--- a/src/mhtree/MHTree.java
+++ b/src/mhtree/MHTree.java
@@ -14,6 +14,7 @@ import mhtree.benchmarking.SearchState;
 
 import java.io.Serializable;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.BitSet;
 import java.util.IntSummaryStatistics;
 import java.util.List;
@@ -22,6 +23,8 @@ import java.util.PriorityQueue;
 import java.util.function.BiFunction;
 import java.util.stream.Collectors;
 
+import static cz.muni.fi.disa.similarityoperators.cover.AbstractRepresentation.Ranked.getRankedIndices;
+
 public class MHTree extends Algorithm implements Serializable {
 
     /**
@@ -172,7 +175,9 @@ public class MHTree extends Algorithm implements Serializable {
     }
 
     public void printStatistics() {
-        IntSummaryStatistics nodeHullObjects = getNodes()
+        List<Node> nodes = getNodes();
+
+        IntSummaryStatistics nodeHullObjects = nodes
                 .stream()
                 .mapToInt(Node::getHullObjectCount)
                 .summaryStatistics();
@@ -182,16 +187,14 @@ public class MHTree extends Algorithm implements Serializable {
                 .mapToInt(LeafNode::getObjectCount)
                 .summaryStatistics();
 
-        int numberOfNodes = getNodes().size();
-
         System.out.println("Leaf object capacity: " + leafCapacity);
         System.out.println("Node degree: " + nodeDegree);
         System.out.println("Object to node distance measurement: " + objectToNodeDistance);
         System.out.println("Insert type: " + insertType);
 
         System.out.println("Number of objects: " + bucketDispatcher.getObjectCount());
-        System.out.println("Number of nodes: " + numberOfNodes);
-        System.out.println("Number of internal nodes: " + (numberOfNodes - leafNodeObjects.getCount()));
+        System.out.println("Number of nodes: " + nodes.size());
+        System.out.println("Number of internal nodes: " + (nodes.size() - leafNodeObjects.getCount()));
         System.out.println("Height: " + root.getHeight());
         System.out.println("Number of leaf nodes: " + leafNodeObjects.getCount());
 
@@ -354,7 +357,15 @@ public class MHTree extends Algorithm implements Serializable {
                     int furthestNodeIndex = nodeDistances.getFurthestIndex(notProcessedNodeIndices);
                     notProcessedNodeIndices.clear(furthestNodeIndex);
 
-                    mergeNodes(furthestNodeIndex, findClosestItems(this::findClosestNodeIndex, furthestNodeIndex, arity - 1, notProcessedNodeIndices));
+                    List<Integer> closestNodeIndices = Arrays
+                            .stream(getRankedIndices(notProcessedNodeIndices, nodeDistances.getDistances(furthestNodeIndex)))
+                            .limit(arity - 1)
+                            .map(node -> node.index)
+                            .collect(Collectors.toList());
+
+                    closestNodeIndices.forEach(notProcessedNodeIndices::clear);
+
+                    mergeNodes(furthestNodeIndex, closestNodeIndices);
                 }
             }
 
@@ -428,23 +439,6 @@ public class MHTree extends Algorithm implements Serializable {
             return resultItemsIndices;
         }
 
-        private int findClosestNodeIndex(List<Integer> indices, BitSet validNodeIndices) {
-            double minDistance = Double.MAX_VALUE;
-            int closestNodeIndex = -1;
-
-            for (int index : indices) {
-                int candidateIndex = nodeDistances.getClosestIndex(index, validNodeIndices);
-                float distance = nodeDistances.getDistance(index, candidateIndex);
-
-                if (distance < minDistance) {
-                    minDistance = distance;
-                    closestNodeIndex = candidateIndex;
-                }
-            }
-
-            return closestNodeIndex;
-        }
-
         private int findClosestObjectIndex(List<Integer> indices, BitSet validObjectIndices) {
             double minDistance = Double.MAX_VALUE;
             int closestObjectIndex = -1;
@@ -522,15 +516,8 @@ public class MHTree extends Algorithm implements Serializable {
                 computeNodeDistances();
             }
 
-            /**
-             * Returns precomputed distance between nodes on indices i and j in {@code nodes}.
-             *
-             * @param i an index of node in {@code nodes}
-             * @param j an index of node in {@code nodes}
-             * @return the distance between nodes on indices i and j in {@code nodes}
-             */
-            private float getDistance(int i, int j) {
-                return distances[i][j];
+            private float[] getDistances(int i) {
+                return distances[i];
             }
 
             private void updateNodeDistances(int nodeIndex) {