         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
+        if (flag) prefix1[offset - 1] = tid;                                     //with tid's whose leaves have to be opened
+        __syncthreads();                                                         //thread barrier, make sure all warps completed the job
+       
+        // step2 
         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;
+        int n_bodies = offset2.y;                                               //Total number of bides extract from the leaves
+        __syncthreads();                                                        // thread barrier to make sure that warps completed their jobs
+
+        direct [tid]  = offset1;                                            //Store a copy of inclusive scan in direct
+        offset1      -= nbody;                                              //convert inclusive int oexclusive scan
+        offset1      += 1;                                                  //add unity, since later prefix0[tid] == 0 used to check barrier
         prefix0[tid] = offset1;
         __syncthreads();
-#endif
 
         int nl_pre = 0;                                                     //Number of leaves that have already been processed
 

    int *lmem,
    int &ngb,
    int &apprCount, int &direCount,
    float4 *boxSizeInfo,
    float4 groupSize,
    float4 *boxCenterInfo,
    float group_eps,
    real4 *body_vel) {


        int *prefix0 = &prefix[  0];
        int *prefix1 = &prefix[DIM];

        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;


        for (int i = n_offset; i < n_offset + n_total; i += DIM)         //nullify part of the array that will be filled with children
          nodes[tid + i] = 0;                                          //but do not touch those parts which has already been filled
        __syncthreads();                                                 //Thread barrier to make sure all warps finished writing data

        bool flag = (split && !leaf) && use_node;                        //Flag = use_node + split + not_a_leaf;Use only non_leaf nodes that are to be split
        if (flag) nodes[offset] = child;                            //Thread with the node that is about to be split
                                                                         //writes the first child in the array of nodes
        /*** in the following 8 lines, we calculate indexes of all the children that have to be walked from the index of the first child***/
        if (flag && nodes[offset + 1] == 0) nodes[offset + 1] = child + 1; 
        if (flag && nodes[offset + 2] == 0) nodes[offset + 2] = child + 2;
        if (flag && nodes[offset + 3] == 0) nodes[offset + 3] = child + 3;
        if (flag && nodes[offset + 4] == 0) nodes[offset + 4] = child + 4;
