edg_wll_ErrorCode edg_wll_GetSubjobHistogram(edg_wll_Context ctx, edg_wlc_JobId parent_jobid, intJobStat **ijs)
 {
 
-        char    *stmt = NULL,*out = NULL, *res_rest;
+        char    *stmt = NULL,*out = NULL;
         edg_wll_Stmt    sh;
         int     f = -1;
 
         edg_wll_ResetError(ctx);
-        trio_asprintf(&stmt,"select int_status from states where jobid='%|Ss'", parent_jobid);
+        trio_asprintf(&stmt,"select int_status from states where (jobid='%|Ss') AND (version='%|Ss')", parent_jobid, INTSTAT_VERSION);
 
         if (stmt==NULL) {
                 return edg_wll_SetError(ctx,ENOMEM, NULL);
         }
 
+/* XXX: Untested  */
+
+/* XXX: This positively does not work, needs finishing: */
+
         if (edg_wll_ExecStmt(ctx,stmt,&sh) >= 0) {
                 f=edg_wll_FetchRow(sh,&out);
                 if (f == 0) {
                         if (out) free(out);
                         out = NULL;
-                        return edg_wll_SetError(ctx, ENOENT, NULL);
+                        edg_wll_SetError(ctx, ENOENT, NULL);
                 }
         }
         edg_wll_FreeStmt(&sh);
         free(stmt);
 
-/* XXX: Untested  */
-
-        *ijs = dec_intJobStat(out, &res_rest);
-        if (res_rest == NULL) {
-                edg_wll_SetError(ctx, EDG_WLL_ERROR_DB_CALL,
-                                "error decoding DB intJobStatus");
-        }
-
-
        return edg_wll_Error(ctx, NULL, NULL);
 }
 
                return edg_wll_SetError(ctx,ENOMEM, NULL);
        }
 
+/* XXX: Untested  */
+
+//printf ("Would like to run SQL statament: %s\n", stmt);
+
         if ((dbret = edg_wll_ExecStmt(ctx,stmt,NULL)) < 0) goto cleanup;
 
        assert(dbret);  /* update should come through OK as the record exists */
 
 {
         char *out;
        int index;
-       for (index=0; index <= itemsNo; index++) asprintf(&out,"%s%d%s", out, item[index],index==itemsNo?"":";");
-        asprintf(&out,"%s%s ", old, out);
+       char *strpom;
+
+       strpom=(char*)calloc(strlen(old)+1,sizeof(char));
+
+       for (index=0; index <= itemsNo; index++) sprintf(strpom,"%s%d%s", strpom, item[index],index==itemsNo?"":";");
+
+        asprintf(&out,"%s%s ", old, strpom);
+       free(strpom);
         free(old);
+
         return out;
 }
 
 
 static int dec_int_array(char* in, char **rest, int *out)
 {
-       int charNo, itemsNo = 0, cindex, iindex = 0;
+       int charNo, itemsNo = 0, cindex, iindex = 0, lenindex;
        char *tempstr;
 
         /* Find out the number of items in the field first */
        }
        else *rest = charNo + 1;
 
-//     out = (int*)calloc(itemsNo,sizeof(int));
        tempstr = (char*)calloc(charNo+1,sizeof(char));
 
        strcpy(tempstr,"");
                        strcpy(tempstr,"");
                        iindex++;
                }
-               else tempstr = strcat(tempstr, in[cindex]); 
+               else {
+                       lenindex=strlen(tempstr);
+                       tempstr[lenindex]=in[cindex];
+                       tempstr[lenindex+1]=0;
+               }
        }
        if (in[cindex] != ' ') out[iindex] = atoi(tempstr);     /* string not terminated with a separator */
 
        free(tempstr);
+       *rest = in + charNo + 1;
 
         return out;
 }
 
        stat = (edg_wll_JobStat *) calloc(1,sizeof(edg_wll_JobStat));
        if (!stat) return stat;
-
        tmp_in = in;
+
         stat->state = dec_int(tmp_in, &tmp_in);
         if (tmp_in != NULL) stat->jobId = dec_jobid(tmp_in, &tmp_in);
         if (tmp_in != NULL) stat->owner = dec_string(tmp_in, &tmp_in);
                            dec_int_array(tmp_in, &tmp_in, stat->children_hist); }
 
        *rest = tmp_in;
+
        return stat;
 }
 
        char *tmp_in;
 
        pubstat = dec_JobStat(in, &tmp_in);
+
        if (tmp_in != NULL) {
                stat = (intJobStat *)calloc(1,sizeof(intJobStat));
        }