     }
 }
 
+(int keys[]) sort_keys(string params[][]) {
+  sort_code =
+"""
+key_string = '%s'
+keys = [int(x) for x in key_string.split(',')]
+keys.sort()
+result = ",".join([str(x) for x in keys])
+""";
+
+  string k[] = keys_string(params);
+  string code = sort_code % (join(k, ","));
+  result = python_persist(code, "result");
+  foreach val, i in split(result, ",")
+  {
+    keys[i] = string2int(val);
+  }
+}
+
 main() {
   string params[][];
-  foreach study1 in studies
+  
+  foreach study1, i in studies
   {
     foreach study2 in studies
     {
-
       if (study1 != study2)
       {
         foreach cutoff in cutoffs

  }

  assert(size(ME_ranks) == size(params), "Number of ME ranks must equal number of xcorrs");
  int keys[] = keys_integer(params);

  int modulo_prio = size(ME_ranks);
  foreach hash_index, r in keys
  {
    string ps[] = params[hash_index];
    int rank = ME_ranks[r];
    // initial priority, modulo priority, rank, record_id, feature file name, study1 name
    start(-r - 1, modulo_prio, rank, ps[0], ps[1], ps[2]);
  }
}

                gpus, feature_file, cache_dir);
            updated_param = python_persist(param_code, "params_json");
            // TODO DB: insert updated_param with mlr_instance_id and record 
            //printf("Updated Params: %s", updated_param);
            //printf("XXX %s: %i", feature_file, prio);

            //results[j] = "0.5";
            results[j] = obj_prio(updated_param,
                             "%00i_%00i_%000i_%0000i" % (mlr_instance_id, restart_number,i,j), prio);
