         prefix[tid] += n_offset - nchild;
         __syncthreads();
 #else
-#if 0
-        inclusive_scan_block<ADDOP<int>, int, DIM2>(prefix, nchild, tid);        // inclusive scan to compute memory offset of each child
-#else
-        int v0 = inclusive_scan_block<ADDOP<int>, int, DIM2>(nchild, tid);        // inclusive scan to compute memory offset of each child
-        prefix[tid] = v0;
-        __syncthreads();
-#endif
-        int n_total = prefix[blockDim.x - 1];                              // fetch total number of children, i.e. offset of the last child -1
-        __syncthreads();                                                   // thread barrier to make sure that warps completed their jobs
-        prefix[tid] += n_offset - nchild;                                  // convert inclusive into exclusive scan for referencing purpose
-        __syncthreads();                                                   // thread barrier
+        int2 offset2 = inclusive_scan_blockS<DIM2>(prefix_shmem, nchild, tid);        // inclusive scan to compute memory offset of each child
+        int  offset = offset2.x;
+        int n_total = offset2.y;
+        offset += n_offset - nchild;
 #endif
 
         for (int i = n_offset; i < n_offset + n_total; i += DIM)         //nullify part of the array that will be filled with children

          __syncthreads();

          //step 1:
          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();

          //step 2:
#if 1 //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
#endif
          nb = direct[prefix1[nl_pre + nl - 1]];                        // number of bodies stored in these leaves


        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

