             }
         }
         func intersects(index1: Int, index2: Int, callback: (Int, Int) -> Void) {
-            guard boxes[index1].overlaps(boxes[index2]) else {
+            guard self.boundingBoxes[index1].overlaps(self.boundingBoxes[index2]) else {
                 return // nothing to do
             }
             let leaf1 = index1 >= inodecount

            lastRowIndex += 1
        }
        self.lastRowIndex = lastRowIndex

        
        for i in 0..<leafBoxes.count {
            let nodeIndex = i+self.inodeCount

    
    init(boxes leafBoxes: [BoundingBox]) {
        // create a complete binary tree of bounding boxes where boxes[0] is the root and left child is 2*index+1 and right child is 2*index+2
        assert(leafBoxes.count > 0)
        let boxes = UnsafeMutablePointer<BoundingBox>.allocate(capacity: 2*leafBoxes.count-1)
        
        self.elementCount = leafBoxes.count
        self.inodeCount = leafBoxes.count-1
        
        var lastRowIndex = 0
