     ymax = NEW_DIMENSION_MAX(y, ymid, ymin, ymax);
     zmin = NEW_DIMENSION_MIN(z, zmid, zmin, zmax);
     zmax = NEW_DIMENSION_MAX(z, zmid, zmin, zmax);
+
+    // set rotation of recursive child
+    #pragma unroll
+    for(int j = 0; j != 8; ++j)
+      codeindex[j] = codeindex_rotations[bits][codeindex[j]];
   }
   codes[i] = code;
 }

  const double y = star.y;
  const double z = star.z;

  uint64_t code = 0;
  #pragma unroll
  for(int i = 0, end = 21; i != end; ++i) {
    code = code << 3;

    const double xmid = GET_MID(xmin, xmax);

      || (x <= xmid && y <= ymid && z >= zmid)
      || (x >= xmid && y >= ymid && z >= zmid)
      || (x <= xmid && y >= ymid && z <= zmid);
    char bits = (bit0 << 2) | (bit1 << 1) | (bit2 << 0);
    bits = codeindex[bits]; // rotate
    code = code | bits;


    xmin = NEW_DIMENSION_MIN(x, xmid, xmin, xmax);
    xmax = NEW_DIMENSION_MAX(x, xmid, xmin, xmax);
