         body_list[laneId] = directM[laneId];                                            //copy list of bodies from previous pass to body_list
 
         // step 1
-        calc_prefix(prefix, flag);                                // inclusive scan on flags to construct array
-        const int offset1 = prefix[laneId];
+        /* binary prefix sum */
+
+        // step 1
+        int n_bodies  = inclusive_scan_warp(prefix, nbody);              // inclusive scan to compute memory offset for each body
+        offset = prefix[laneId];
 
         // step 2
-        int n_bodies  = calc_prefix(prefix, nbody);              // inclusive scan to compute memory offset for each body
-        offset = prefix[laneId];
-
-        if (flag) prefix[offset1 - 1] = laneId;                             //with tidś whose leaves have to be opened
+        if (flag) prefix[warp_exclusive_scan(flag)] = laneId;   //with tidś whose leaves have to be opened
 
         directM[laneId]  = offset;                                       //Store a copy of inclusive scan in direct
         offset       -= nbody;                                              //convert inclusive int oexclusive scan

  return partial;
}
  template<const int SIZE2>
__device__ __forceinline__ int inclusive_segscan_warp(int value, const int distance)
{

#if 0

  return mask;
}

__device__ __forceinline__ int inclusive_segscan_warp(
    int *shmem, const int packed_value, int &dist_block, int &nseg)
{
  const int  flag = packed_value < 0;
