     unsigned int blocksize = funcAttr.maxThreadsPerBlock > 256 ? 256 : funcAttr.maxThreadsPerBlock;
     unsigned int blocks = (nActiveSphereIndices / blocksize) + 1;
     PartitionLeafIndices<<<blocks, blocksize>>>
-        (RawPointer(sphereIndices) + leafSphereIndices, // starts at the first active index
-         RawPointer(sphereIndexPartition) + leafSphereIndices, // starts at the first active owner
-         RawPointer(spherePartitions) + leafNodes, // starts at the first active partition
+        (RawPointer(sphereIndices),
+         RawPointer(sphereIndexPartition),
+         RawPointer(spherePartitions) + leafNodes, // Starts at the first active partition
          RawPointer(isLeaf),
          RawPointer(leafSpheresStartIndex),
          RawPointer(leafNodeIndices),

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

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

    // 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 partition = nodePartitions[owner];
    
    const bool leaf = isLeaf[owner];

    // Compute the new index of the data
    const unsigned int partitioningBegin = leaf ? 
        leafStartIndex[owner] :
        partition.x - nNewLeafIndices;
    // Since id's index into active data and partitions contain global indices,
    // we need to add nOldLeafIndices.
    const unsigned int partitionOffset = id + nOldLeafIndices - partition.x;
    const unsigned int dataIndex = partitioningBegin + partitionOffset;
    
    unsigned int* newIndices = leaf ? leafIndices : nextIndices;
    newIndices[dataIndex] = 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

};

__global__
void CreateNewLeafNodes(const uint2* const rayPartitions,
                        const uint2* const spherePartitions,
                        const bool* isLeafNode,
                        const unsigned int* leafNodeIndices,
                        const unsigned int* newSpherePartitionBegins,
                        uint2* nextRayPartitions,
                        uint2* nextSpherePartitions,
                        const unsigned int nActiveNodes,
                        const unsigned int nNewLeafs,
                        const unsigned int nOldLeafSphereIndices,
                        const unsigned int nNewLeafSphereIndices) {

    const unsigned int id = threadIdx.x + blockDim.x * blockIdx.x;
    
