Index: /trunk/ippTools/src/dettool.c
===================================================================
--- /trunk/ippTools/src/dettool.c	(revision 12065)
+++ /trunk/ippTools/src/dettool.c	(revision 12066)
@@ -35,5 +35,5 @@
 static bool definebydetrunMode(pxConfig *config);
 static bool runsMode(pxConfig *config);
-static bool orphanrunMode(pxConfig *config);
+static bool childlessrunMode(pxConfig *config);
 static bool inputMode(pxConfig *config);
 static bool rawMode(pxConfig *config);
@@ -107,5 +107,5 @@
         MODECASE(DETTOOL_MODE_DEFINEBYDETRUN,   definebydetrunMode);
         MODECASE(DETTOOL_MODE_RUNS,             runsMode);
-        MODECASE(DETTOOL_MODE_ORPHANRUN,        orphanrunMode);
+        MODECASE(DETTOOL_MODE_CHILDLESSRUN,     childlessrunMode);
         MODECASE(DETTOOL_MODE_INPUT,            inputMode);
         MODECASE(DETTOOL_MODE_RAW,              rawMode);
@@ -492,5 +492,5 @@
     }
 
-    // start a transaction so we don't end up with orphaned det_ids
+    // start a transaction so we don't end up with childlessed det_ids
     if (!psDBTransaction(config->dbh)) {
         psError(PS_ERR_UNKNOWN, false, "database error");
@@ -1142,5 +1142,5 @@
     }
 
-    // start a transaction so we don't end up with orphaned det_ids
+    // start a transaction so we don't end up with childlessed det_ids
     if (!psDBTransaction(config->dbh)) {
         psError(PS_ERR_UNKNOWN, false, "database error");
@@ -1572,5 +1572,5 @@
 
 
-    // start a transaction so we don't end up with orphaned det_ids
+    // start a transaction so we don't end up with childlessed det_ids
     if (!psDBTransaction(config->dbh)) {
         psError(PS_ERR_UNKNOWN, false, "database error");
@@ -1720,17 +1720,25 @@
 }
 
-static bool orphanrunMode(pxConfig *config)
+static bool childlessrunMode(pxConfig *config)
 {
     PS_ASSERT_PTR_NON_NULL(config, false);
 
+    bool status = false;
+    psU64 limit = psMetadataLookupU64(&status, config->args, "-limit");
+    if (!status) {
+        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -limit");
+        return false;
+    }
+
     psString query = psStringCopy(
-            "SELECT\n"
+            "SELECT DISTINCT\n"
             "   detRun.*\n"
             " FROM detRun\n"
             " LEFT JOIN detRun as foo\n"
             "   ON foo.parent = detRun.det_id\n"
-            " WHERE"
-            "   detRun.state = 'stop'"
-            "   AND detRun.mode = 'master'"
+            " WHERE\n"
+            "   detRun.state = 'stop'\n"
+            "   AND detRun.mode = 'master'\n"
+            "   AND foo.det_id IS NULL\n"
         );
 
@@ -1741,4 +1749,11 @@
     }
 
+    // treat limit == 0 as "no limit"
+    if (limit) {
+        psString limitString = psDBGenerateLimitSQL(limit);
+        psStringAppend(&query, " %s", limitString);
+        psFree(limitString);
+    }
+
     if (!p_psDBRunQuery(config->dbh, query)) {
         psError(PS_ERR_UNKNOWN, false, "database error");
@@ -1755,5 +1770,5 @@
     if (!psArrayLength(output)) {
         // XXX check psError here
-        psError(PS_ERR_UNKNOWN, false, "no orphan detRun rows found");
+        psError(PS_ERR_UNKNOWN, false, "no childless detRun rows found");
         psFree(output);
         return true;
Index: /trunk/ippTools/src/dettool.h
===================================================================
--- /trunk/ippTools/src/dettool.h	(revision 12065)
+++ /trunk/ippTools/src/dettool.h	(revision 12066)
@@ -30,5 +30,5 @@
     DETTOOL_MODE_DEFINEBYDETRUN,
     DETTOOL_MODE_RUNS,
-    DETTOOL_MODE_ORPHANRUN,
+    DETTOOL_MODE_CHILDLESSRUN,
     DETTOOL_MODE_INPUT,
     DETTOOL_MODE_RAW,
Index: /trunk/ippTools/src/dettoolConfig.c
===================================================================
--- /trunk/ippTools/src/dettoolConfig.c	(revision 12065)
+++ /trunk/ippTools/src/dettoolConfig.c	(revision 12066)
@@ -242,9 +242,11 @@
             "use the simple output format", false);
 
-    // -orphanrun
-    psMetadata *orphanrunArgs = psMetadataAlloc();
-    psMetadataAddStr(orphanrunArgs, PS_LIST_TAIL, "-det_type",  0,
+    // -childlessrun
+    psMetadata *childlessrunArgs = psMetadataAlloc();
+    psMetadataAddStr(childlessrunArgs, PS_LIST_TAIL, "-det_type",  0,
             "search for type of detrend run", NULL);
-    psMetadataAddBool(orphanrunArgs, PS_LIST_TAIL, "-simple",  0,
+    psMetadataAddU64(childlessrunArgs, PS_LIST_TAIL, "-limit",  0,
+            "limit result set to N items", 0);
+    psMetadataAddBool(childlessrunArgs, PS_LIST_TAIL, "-simple",  0,
             "use the simple output format", false);
 
@@ -796,5 +798,5 @@
     PXTOOL_MODE("-raw",             DETTOOL_MODE_RAW,           rawArgs);
     PXTOOL_MODE("-runs",            DETTOOL_MODE_RUNS,          runsArgs);
-    PXTOOL_MODE("-orphanrun",       DETTOOL_MODE_ORPHANRUN ,    orphanrunArgs);
+    PXTOOL_MODE("-childlessrun",    DETTOOL_MODE_CHILDLESSRUN,  childlessrunArgs);
     PXTOOL_MODE("-input",           DETTOOL_MODE_INPUT,         inputArgs);
     PXTOOL_MODE("-toprocessedimfile", DETTOOL_MODE_TOPROCESSEDIMFILE, toprocessedimfileArgs);
