         let elementCount2 = other.elementCount
         let boxes1 = self.boundingBoxes
         let boxes2 = other.boundingBoxes
+        let lastRowIndex1 = self.lastRowIndex
+        let lastRowIndex2 = other.lastRowIndex
         func intersects(index: Int, callback: (Int, Int) -> Void) {
             if BVH.isLeaf(index, elementCount: elementCount1) { // if it's a leaf node
-                let elementIndex = self.leafNodeIndexToElementIndex(index)
+                let elementIndex = BVH.leafNodeIndexToElementIndex(index, elementCount: elementCount1, lastRowIndex: lastRowIndex1)
                 callback(elementIndex, elementIndex)
             }
             else {

            let leaf1: Bool = BVH.isLeaf(index1, elementCount: elementCount1)
            let leaf2: Bool = BVH.isLeaf(index2, elementCount: elementCount2)
            if leaf1, leaf2 {
                let elementIndex1 = self.leafNodeIndexToElementIndex(index1)
                let elementIndex2 = other.leafNodeIndexToElementIndex(index2)
                callback(elementIndex1, elementIndex2)
            }
            else if leaf1 {

            elementIndex += elementCount
        }
        return elementIndex
    }
    
    private static func isLeaf(_ index: Int, elementCount: Int) -> Bool {
