           __syncthreads();
 
           //step 1:
-          if (flag && (direct[tid] <= nb) && (prefix0[tid] > 0))        //make sure that the thread indeed carries a leaf
+          if (flag && (directM[tid] <= nb) && (prefix0[tid] > 0))        //make sure that the thread indeed carries a leaf
             body_list[n_direct + prefix0[tid] - 1] = 1;                 //whose bodies will be extracted
           __syncthreads();
 
           //step 2:
-#ifdef OLDPREFIX
-          int nl = calc_prefix<DIM2>(nb, &body_list[n_direct], tid);
-#else
           int nl = inclusive_scan_array<DIM2>              // inclusive scan to compute number of leaves to process
             (&body_list[n_direct], prefix_shmem, nb, tid);            // to make sure that there is enough shared memory for bodies
-#endif
-          nb = direct[prefix1[nl_pre + nl - 1]];                        // number of bodies stored in these leaves
+          nb = directM[prefix1[nl_pre + nl - 1]];                        // number of bodies stored in these leaves
 
           // step 3:
           for (int i = n_direct; i < n_direct + nb; i += DIM) {          //segmented fill of the body_list
             int j = prefix1[nl_pre + body_list[i + tid] - 1];            // compute the first body in shared j-body array
             body_list[i + tid] = (i + tid - n_direct) -                 //add to the index of the first j-body in a child
-              (prefix0[j] - 1) + sh_body[j];         //the index of the first child in body_list array
+              (prefix0[j] - 1) + sh_body[j];                            //the index of the first child in body_list array
           }
           __syncthreads();
 



        for (int i = n_offset; i < n_offset + n_total; i += DIM)         //nullify part of the array that will be filled with children
          nodes[tid + i] = 0;                                          //but do not touch those parts which has already been filled
        __syncthreads();                                                 //Thread barrier to make sure all warps finished writing data

        bool flag = (split && !leaf) && use_node;                        //Flag = use_node + split + not_a_leaf;Use only non_leaf nodes that are to be split
        if (flag) nodes[offset] = child;                            //Thread with the node that is about to be split
                                                                         //writes the first child in the array of nodes
        /*** in the following 8 lines, we calculate indexes of all the children that have to be walked from the index of the first child***/
        if (flag && nodes[offset + 1] == 0) nodes[offset + 1] = child + 1; 
        if (flag && nodes[offset + 2] == 0) nodes[offset + 2] = child + 2;
        if (flag && nodes[offset + 3] == 0) nodes[offset + 3] = child + 3;
        if (flag && nodes[offset + 4] == 0) nodes[offset + 4] = child + 4;
        if (flag && nodes[offset + 5] == 0) nodes[offset + 5] = child + 5;
        if (flag && nodes[offset + 6] == 0) nodes[offset + 6] = child + 6;
        if (flag && nodes[offset + 7] == 0) nodes[offset + 7] = child + 7;
        __syncthreads();

        n_offset += n_total;    //Increase the offset in the array by the number of newly added nodes

      n_nodes1 += n_offset;
      if (n_offset > 0)
      { 
        nstack[ACCS<SHIFT>(n_stack1)] = nodesM[tid];   n_stack1++; 
        if((n_stack1 - c_stack0) >= (LMEM_STACK_SIZE << SHIFT))
        {
          //We overwrote our current stack
