         
         
         // %5 of free memory shoudl be enough, we have almsot no variables in these kernels
-        size_t total_pixels              = image_size[0] * image_size[1]  * image_size[2] ;
-        size_t mem_slice_image           = sizeof(float)* image_size[0] * image_size[1]  ;
-        size_t mem_size_image            = sizeof(float)* total_pixels;
+       size_t total_pixels           = image_size[0] * image_size[1] * image_size[2] ;
+       const size_t pixels_per_slice = image_size[0] * image_size[1] ;
+       const size_t mem_slice_image  = sizeof(float)* pixels_per_slice  ;
+       const size_t mem_size_image   = sizeof(float)* total_pixels;
         
         // Decide how are we handling the distribution of computation
         size_t mem_img_each_GPU;

                        if (dev>0){
                            // U
                            cudaSetDevice(dev-1);
                            cudaMemcpyAsync(buffer_u,  d_u[dev-1] +slices_per_split+buffer_pixels, buffer_pixels*sizeof(float), cudaMemcpyDeviceToHost,stream[(dev-1)*nStream_device+1]);
                            cudaMemcpyAsync(buffer_px, d_px[dev-1]+slices_per_split+buffer_pixels, buffer_pixels*sizeof(float), cudaMemcpyDeviceToHost,stream[(dev-1)*nStream_device+2]);
                            cudaMemcpyAsync(buffer_py, d_py[dev-1]+slices_per_split+buffer_pixels, buffer_pixels*sizeof(float), cudaMemcpyDeviceToHost,stream[(dev-1)*nStream_device+3]);
                            cudaMemcpyAsync(buffer_pz, d_pz[dev-1]+slices_per_split+buffer_pixels, buffer_pixels*sizeof(float), cudaMemcpyDeviceToHost,stream[(dev-1)*nStream_device+4]);
                            
                            
                            cudaSetDevice(dev);

                
                // Copy image to memory
                for (dev = 0; dev < deviceCount; dev++){
                    // Precompute indices and needed bytes
                    curr_slices=((sp*deviceCount+dev+1)*slices_per_split<image_size[2])?  slices_per_split:  image_size[2]-slices_per_split*(sp*deviceCount+dev);
                    curr_pixels=curr_slices*pixels_per_slice;
                    linear_idx_start=pixels_per_slice*slices_per_split*(sp*deviceCount+dev);
                    
                    // Check if its the first or last chunck
                    is_last_chunk=!((sp*deviceCount+dev)<deviceCount*splits-1);
