         var j = hi - 1
         
         while true {
-            while array[i].kdDimension(kdDimension) < pivot.kdDimension(kdDimension) {
+            while values[i].kdDimension(kdDimension) < kdDimensionOfPivot {
                 i += 1
             }
-            while lo < j && array[j].kdDimension(kdDimension) >= pivot.kdDimension(kdDimension) {
+            while lo < j && values[j].kdDimension(kdDimension) >= kdDimensionOfPivot {
                 j -= 1
             }
             guard i < j else {
                 break
             }
-            array.swapAt(i, j)
-        }
-        
-        // Swap the pivot element with the first element that is >= 
+            values.swapAt(i, j)
+        }
+        
+        // Swap the pivot element with the first element that is >=
         // the pivot. Now the pivot sits between the < and >= regions and the
         // array is properly partitioned.
-        array.swapAt(i, hi)
+        values.swapAt(i, hi)
         return i
     }
     

    indirect case node(left: KDTree<Element>, value: Element, dimension: Int, right: KDTree<Element>)
}

extension KDTree {
    public init(values: [Element], depth: Int = 0) {
        guard !values.isEmpty else {

    /// right partition.
    ///
    /// - Parameters:
    ///   - values: the pointer to the values
    ///   - kdDimension: the dimension sorted over
    /// - Returns: the index of the pivot element in the pointer
    private static func partitionHoare(_ values: UnsafeMutablePointer<Element>, startIndex lo: Int, endIndex: Int, kdDimension: Int) -> Int {
        let hi = endIndex - 1
        guard lo < hi else { return lo }
        
        let randomIndex = Int.random(in: lo...hi)
        values.swapAt(hi, randomIndex)
        
        let kdDimensionOfPivot = values[hi].kdDimension(kdDimension)
        
        // This loop partitions the array into four (possibly empty) regions:
        //   [lo   ...    i] contains all values < pivot,
