           __syncthreads();
 
           //step 1:
+#if 0
           if (flag && (direct[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();
+#else
+          if (flag && (direct[tid] <= nb) && (offset1 > 0))        //make sure that the thread indeed carries a leaf
+            body_list[n_direct + offset1 - 1] = 1;                 //whose bodies will be extracted
+          __syncthreads();
+#endif
 
           //step 2:
-#if 1 //def OLDPREFIX
+#if 0 //def OLDPREFIX
           int nl = calc_prefix<DIM2>(nb, &body_list[n_direct], tid);
 #else
-          int nl = inclusive_scan_array<ADDOP<int>, int>              // inclusive scan to compute number of leaves to process
-            (&body_list[n_direct], nb, tid);            // to make sure that there is enough shared memory for bodies
+          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
 


#endif

  template<class OP, class T, const int BLOCKDIM2>
__device__ __inline__ T inclusive_scan_block(T v_in, const unsigned int idx) 
{
  __shared__ T shdata[WARP_SIZE];
  const unsigned int laneId = idx & (WARP_SIZE - 1);
  const unsigned int warpId = idx >> WARP_SIZE2;

  T val = inclusive_scan_warp<OP, T, WARP_SIZE2>(v_in, idx);
  if (31 == laneId) shdata[warpId] = val;
  __syncthreads();

  if (0 == warpId) shdata[idx] = inclusive_scan_warp<OP, T, BLOCKDIM2 - WARP_SIZE2>(shdata[idx], idx);
  __syncthreads();

  if (warpId > 0) val = OP::apply(shdata[warpId - 1], val);

  return val; 
}



#endif

  return result;
}

  template <const int levels>
__device__ __forceinline__ uint inclusive_scan_warp(int mysum, const int idx)
{
  for(int i = 0; i < levels; ++i)
    mysum = shfl_scan_add_step(mysum, 1 << i);
  return mysum;
}

#else

  template<const int SIZE2>
__device__ __forceinline__ int inclusive_scan_warp(int value, const unsigned int idx) 
{
  const unsigned int laneId = idx & 31;

