           __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 0 //def OLDPREFIX
+#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[tid] = direct[tid];                                            //copy list of bodies from previous pass to body_list
        sh_body  [tid] = jbody;                                                  //store the leafs first body id into shared memory

        // step 1
#if 0
        int v0 = inclusive_scan_block<DIM2>(prefix_shmem, (int)flag, tid);       // inclusive scan on flags to construct array
        prefix0[tid] = v0;
        __syncthreads();

        if (flag) prefix1[prefix0[tid] - 1] = tid;                             //with tidś whose leaves have to be opened
        __syncthreads();                                                      //thread barrier, make sure all warps completed the job
#else
        offset = inclusive_scan_block<DIM2>(prefix_shmem, (int)flag, tid);       // inclusive scan on flags to construct array
        if (flag) prefix1[offset - 1] = tid;                             //with tidś whose leaves have to be opened
#endif

        // step 2
#if 0
        int v0 = inclusive_scan_block<DIM2>(prefix_shmem, nbody, tid);        // inclusive scan to compute memory offset for each body
        prefix0[tid] = v0;
        __syncthreads();
        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

        direct [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
#else
        offset2 = inclusive_scan_blockS<DIM2>(prefix_shmem, nbody, tid);        // inclusive scan to compute memory offset for each body
        int offset1  = offset2.x;
        int n_bodies = offset2.y;

        direct[tid] = offset1;
        offset1    -= nbody;
        offset1    += 1;
        prefix0[tid] = offset1;
        __syncthreads();
#endif

        int nl_pre = 0;                                                     //Number of leaves that have already been processed


          n_bodies     -= nb;                                   //subtract from n_bodies number of bodies that have been extracted
          nl_pre       += nl;                                   //increase the number of leaves that where processed
          direct [tid] -= nb;                                   //subtract the number of extracted bodies in this pass
          prefix0[tid] = max(prefix0[tid] - nb, 0);             //same here, but do not let the number be negative (GT200 bug!?)
          n_direct     += nb;                                  //increase the number of bodies to be procssed

          while(n_direct >= DIM) 
