         sh_body  [tid] = jbody;                                                  //store the leafs first body id into shared memory
 
         // step 1
-#ifdef OLDPREFIX
-        calc_prefix<DIM2>(prefix0, tid, flag);
-#else
-        inclusive_scan_block<ADDOP<int>, int>(prefix0, (int)flag, tid);       // inclusive scan on flags to construct array
-#endif
-
-        if (flag) prefix1[prefix0[tid] - 1] = tid;                             //with tidś whose leaves have to be opened
+        calc_prefix<DIM2>(prefix, tid, flag);                                // inclusive scan on flags to construct array
+        offset = prefix[tid];
+
+        if (flag) prefix1[offset - 1] = tid;                             //with tidś whose leaves have to be opened
         __syncthreads();                                                      //thread barrier, make sure all warps completed the job
 
         // step 2
-#ifdef OLDPREFIX
-        int n_bodies  = calc_prefix<DIM2>(prefix0, tid, nbody);
-#else
-        inclusive_scan_block<ADDOP<int>, int>(prefix0, nbody, tid);        // inclusive scan to compute memory offset for each body
-        int n_bodies = prefix0[blockDim.x - 1];                            //Total number of bides extract from the leaves
-        __syncthreads();                                                   // thread barrier to make sure that warps completed their jobs
-#endif
-
-        directM[tid]  = prefix0[tid];                                       //Store a copy of inclusive scan in direct
-        prefix0[tid] -= nbody;                                              //convert inclusive int oexclusive scan
-        prefix0[tid] += 1;                                                  //add unity, since later prefix0[tid] == 0 used to check barrier
+        int n_bodies  = calc_prefix<DIM2>(prefix, tid, nbody);              // inclusive scan to compute memory offset for each body
+        offset = prefix[tid];
+
+        directM[tid]  = offset;                                       //Store a copy of inclusive scan in direct
+        offset       -= nbody;                                              //convert inclusive int oexclusive scan
+        offset       += 1;                                                  //add unity, since later prefix0[tid] == 0 used to check barrier
+        prefix0[tid]  = offset;
 
         int nl_pre = 0;                                                     //Number of leaves that have already been processed
 


  prefix[tid] += value;
  __syncthreads();
  
  x = prefix[DIM - 1];
  __syncthreads();
  return x;
#endif
}

template<int SHIFT>
__forceinline__ __device__ int ACCS(const int i)
{
  return (i & ((LMEM_STACK_SIZE << SHIFT) - 1))*blockDim.x + threadIdx.x;

    int iflag = BTEST(tid < d);
    int ai = (((tid2 + 1) << offset) - 1) & iflag;
    int bi = (((tid2 + 2) << offset) - 1) & iflag;

    prefix[bi] += prefix[ai] & iflag;
    offset++;
  }
