     auto extents = grid.bbox.extents();
     auto dims = grid.dims << grid.shift;
     auto cell_size = extents / vec3(dims);
+    auto grid_inv = vec3(dims) / extents;
 
     set_global(hagrid::grid_dims,  &dims);
     set_global(hagrid::grid_min,   &grid.bbox.min);
     set_global(hagrid::cell_size,  &cell_size);
+    set_global(hagrid::grid_inv,   &grid_inv);
     set_global(hagrid::grid_shift, &grid.shift);
 
     for (int i = 0; i < iters - 1; i++)
-        expansion_iter<true>(grid, prims, new_cells, cell_flags);
-    expansion_iter<false>(grid, prims, new_cells, cell_flags);
+        expansion_iter<false>(grid, prims, new_cells, cell_flags);
+    expansion_iter<true>(grid, prims, new_cells, cell_flags);
 
     mem.free(cell_flags);
     mem.free(new_cells);

                i = get<axis1>(cell.min);
                j += k2;
                k2 = get<axis2>(grid_dims);
                if (j >= get<axis2>(cell.max)) {
                    break;
                }
            }
        }
    }

static __constant__ ivec3 grid_dims;
static __constant__ vec3  grid_min;
static __constant__ vec3  cell_size;
static __constant__ vec3  grid_inv;
static __constant__ int   grid_shift;

/// Gets the component of the given vector on the specified axis
