 
 int minImpurity(long long *keys, int *counts, int *out, float *outv, int *jc, int *fieldlens, 
                 int ntrees, int nnodes, int ncats, int nsamps, int impType) {
+  // Note: its safe to round ncats up to a multiple of 32, since its only used to split shmem
   int ny = min(32, DBSIZE/ncats);
   dim3 tdim(32, ny, 1);
   int ng = min(64, 1L*ntrees*nnodes*nsamps);

      jtodo = min(32, jc1 - j);
      for (k = 0; k < jtodo; k++) {                        // Sequentially update counts so that each thread
        if (threadIdx.x == k) {                            // in this warp gets the old and new counts
          ccnt = catcnt[icat + ncats * threadIdx.y];       // save data for item k in thread k
          cnew = ccnt + cnt;
          catcnt[icat + ncats * threadIdx.y] = cnew;
        }

        lastival = tmp;
        lastimpty = tmpx;
      }

      if (ival == lastival) lastimpty = 1e7f;             // Eliminate values which are not at value boundaries
      if (lastimpty < minimpty) {
        minimpty = lastimpty;
