Index: trunk/pstamp/src/pstampparse.c
===================================================================
--- trunk/pstamp/src/pstampparse.c	(revision 18550)
+++ trunk/pstamp/src/pstampparse.c	(revision 18551)
@@ -304,8 +304,12 @@
                         (_id), NULL, false, NULL))
 
-#define warpIDForCam(_opt, _id) \
-        lastID(runQuery((_opt), "SELECT %s from warpInputExp  WHERE cam_id = %s", "warp_id", \
+#define fakeIDForCam(_opt, _id) \
+        lastID(runQuery((_opt), "SELECT %s from fakeRun  WHERE cam_id = %s", "fake_id", \
                             (_id), NULL, false, NULL))
 
+#define warpIDForFake(_opt, _id) \
+        lastID(runQuery((_opt), "SELECT %s from warpRun  WHERE fake_id = %s", "warp_id", \
+                            (_id), NULL, false, NULL))
+
 
 
@@ -317,7 +321,13 @@
         return NULL;
 
-    psArray *chip_files = runQuery(options,
-                        "SELECT %s from chipProcessedImfile WHERE chip_id = %s AND class_id = '%s'",
+    psString query = NULL;
+    psStringAppend(&query, "SELECT %s from chipProcessedImfile WHERE chip_id = %s", "%s", "%s");
+    if (class_id && (strcmp(class_id, "null") != 0)) {
+        psStringAppend(&query, " AND class_id = '%s'", "%s");
+    }
+
+    psArray *chip_files = runQuery(options, query,
                         "uri", chip_id, class_id, true, NULL);
+    psFree(query);
     psFree(chip_id);
 
@@ -336,5 +346,11 @@
         return NULL;
 
-    psString warp_id = warpIDForCam(options, cam_id);
+    psString fake_id = fakeIDForCam(options, cam_id);
+    if (fake_id == NULL)
+        return NULL;
+
+    psString warp_id = warpIDForFake(options, fake_id);
+    if (warp_id == NULL)
+        return NULL;
 
     psArray *warp_files = runQuery(options,
@@ -344,4 +360,5 @@
 
     psFree(warp_id);
+    psFree(fake_id);
     psFree(cam_id);
     psFree(chip_id);
@@ -361,5 +378,9 @@
         return NULL;
 
-    psString warp_id = warpIDForCam(options, cam_id);
+    psString fake_id = fakeIDForCam(options, cam_id);
+    if (fake_id == NULL)
+        return NULL;
+
+    psString warp_id = warpIDForFake(options, fake_id);
     if (warp_id == NULL)
         return NULL;
@@ -369,4 +390,5 @@
 
     psFree(warp_id);
+    psFree(fake_id);
     psFree(cam_id);
     psFree(chip_id);
@@ -402,5 +424,11 @@
         return NULL;
 
-    psString warp_id = warpIDForCam(options, cam_id);
+    psString fake_id = fakeIDForCam(options, cam_id);
+    if (fake_id == NULL)
+        return NULL;
+
+    psString warp_id = warpIDForFake(options, fake_id);
+    if (warp_id == NULL)
+        return NULL;
 
     psArray *diffIDs = runQuery(options,
@@ -409,4 +437,5 @@
 
     psFree(warp_id);
+    psFree(fake_id);
     psFree(cam_id);
     psFree(chip_id);
@@ -632,6 +661,5 @@
         // or are there simply no images matching the request
         fprintf(stderr, "No matching images found.\n");
-        // don't return an error
-        return true;
+        return false;
     }
 
