const double sp = case_data_idx (cc, ROC_TN)->f /
            (case_data_idx (cc, ROC_TN)->f + case_data_idx (cc, ROC_FP)->f);
 
+          if (coord_idx >= n_coords)
+            {
+              assert (coord_idx == n_coords);
+              pivot_category_create_leaf (
+                coordinates->root, pivot_value_new_integer (++n_coords));
+            }
+
           pivot_table_put3 (
             table, 0, coord_idx, var_idx,
             pivot_value_new_var_value (roc->vars[i],
           coord_idx++;
        }
 
-      if (coord_idx > n_coords)
-        n_coords = coord_idx;
-
       casereader_destroy (r);
     }
 
-  for (size_t i = 0; i < n_coords; i++)
-    pivot_category_create_leaf (coordinates->root,
-                                pivot_value_new_integer (i + 1));
-
   pivot_table_submit (table);
 }
 
 
                  struct pivot_value *value)
 {
   assert (n == table->n_dimensions);
+  for (size_t i = 0; i < n; i++)
+    assert (dindexes[i] < table->dimensions[i]->n_leaves);
 
   if (value->type == PIVOT_VALUE_NUMERIC && !value->numeric.format.w)
     {