                                                     RawPointer(nextRayPartitions) + leafNodes);
         //std::cout << "nextRayPartitions:\n" << nextRayPartitions << std::endl;
 
-        // std::cout << "nextRayPartitions:\n" << std::endl;
-        // for (int i = 0; i < nextRayPartitions.size(); ++i) {
-        //     uint2 partition = nextRayPartitions[i];
-        //     unsigned int min = rayMortonCodes[partition.x];
-        //     unsigned int max = rayMortonCodes[partition.y-1];
-        //     cout << i << ": " << partition << ", min: " << Bitmap(min) << ", max: " << Bitmap(max) << endl;
-        // }
-        
 
         // Use the new partitions to approximate the left and right bounds for
         // ray partitions and split the geometry. TODO All of these

    // leaf, then it is the old node index minus the number of new leafs created
    // (plus the number of old leaf nodes that was subtracted earlier). Now
    // how's that for documentation!
    unsigned int* newOwners = leaf ? leafOwners : nextOwners;
    unsigned int newOwner = leaf ? 
        leafNodeIndices[owner] + nOldLeafs : 
        owner + nOldLeafs - nNewLeafs;
        
    newOwners[dataIndex] = newOwner;
}

bool MortonDacrtNodes::CreateLeafNodes() {

                          const unsigned int nOldLeafs, // number of leafs prior to checking for new ones.
                          const unsigned int nNewLeafs, // number of new leafs
                          // Results
                          unsigned int* nextIndices,
                          unsigned int* nextOwners) {

    unsigned int id = threadIdx.x + blockDim.x * blockIdx.x;
    if (id >= nActiveIndices) return;
    
    id += nOldLeafIndices;

    // Owners are global, so it's minus the number of leaves to get the owner of
    // the active indices.
    const unsigned int owner = owners[id] - nOldLeafs;
    const uint2 partitioning = nodePartitions[owner];
    
    const bool leaf = isLeaf[owner];

    // Compute the new index of the data
    const unsigned int partitioningBegin = leaf ? 
        leafSphereBeginEntries[owner] + nOldLeafIndices: 
        partitioning.x + nNewLeafIndices;

    // Offset of the data in the partitioning relative to the beginning.
    const unsigned int offset = id - partitioning.x;
    const unsigned int newEntry = partitioningBegin + offset;
    
    nextIndices[newEntry] = indices[id];

    // Compute the new owner of the data. If it has been moved to a leaf node,
    // then the new owner is the addition of the number of old leafs and the
