         -- RAISE NOTICE 'loop';
         tmid    := (tlow + thigh)/2;
         -- try a new position for the cut
-        tline   := ST_Translate(cutline,0,-tmid);
-
-        -- split with horizontal line, get two polygons back
-        -- sort them in north-to-south order
+        tline   := ST_Translate(cutline,0,tmid);
+
+        -- split with horizontal line, we might
+        -- get back more than two pieces (depending on the shape of poly).
+        -- so we need to collect those above, and those below the cut.
         tsplit  := (
-            SELECT
-            array_agg(b.piece)
-            FROM (
+            WITH parts AS (
                 SELECT 
                 a.piece
                 FROM (
                     SELECT ((ST_Dump((ST_Split(poly, tline)))).geom) AS piece
                 ) a
-                ORDER BY ST_YMax(piece) DESC
-            ) b
+            ), U AS (
+                SELECT
+                ST_Multi(ST_Collect(piece)) AS shape
+                FROM parts
+                WHERE ST_YMin(piece) >= ST_YMin(poly) + tmid
+            ), D AS (
+                SELECT
+                ST_Multi(ST_Collect(piece)) AS shape
+                FROM parts
+                WHERE ST_YMin(piece) < ST_YMin(poly) + tmid
+            )
+            SELECT
+            ARRAY[U.shape, D.shape]
+            FROM U,D
         );
-        tarea := ST_Area(tsplit[1]);
+
+        tarea := ST_Area(tsplit[updown]);
 
         -- re-adjust the range we're searching for the split
         -- depending on overshot/undershot relatve to the target area.
-        IF tarea > area THEN
-            -- overshot  the target area
+        IF    tarea > area AND updown = 1 THEN
+            -- overshot  the upper target area
+            tlow  := tmid;
+        ELSIF tarea < area AND updown = 1 THEN
+            -- undershot the upper target area
             thigh := tmid;
-        ELSIF tarea < area THEN
-            -- undershot the target area
+        ELSIF tarea > area AND updown = 2 THEN
+            -- overshot  the lower target area
+            thigh := tmid;
+        ELSIF tarea < area AND updown = 2 THEN
+            -- undershot the lower target area
             tlow  := tmid;
         END IF;
 


-- input:
-- receives as parameters the initial polygon, the desired area,
-- the x/y min/max of the bbox for the polygon.
--
-- output:

        RETURN NULL;
    END IF;

    IF p_area < target_area THEN
        -- the input polygon is too small and we won't be able to
        -- to find a parcel with the required area.
        RAISE NOTICE 'the polygon area is too small';
