       SELECT unnest($1) AS co_id
     ) a
     WHERE sg.cityobject_id = a.co_id
+      AND sg.parent_id IS NULL
   UNION ALL
     SELECT sg.id, sg.parent_id, g.level + 1 AS level 
       FROM surface_geometry sg, geometry g
       WHERE sg.parent_id = g.id
 )
-SELECT array_agg(g.g_id) AS result_array FROM (
-  SELECT unnest(citydb_pkg.batch_delete_geometry(batch.ids)) AS g_id FROM (
-    SELECT array_agg(id) AS ids
-      FROM geometry
-      GROUP BY level ORDER BY level DESC
-  ) batch
-) g;
+SELECT citydb_pkg.batch_delete_geometry(id ORDER BY level DESC) AS result_array
+  FROM geometry;
 $$
 LANGUAGE sql STRICT;
 

      FROM cityobject_genericattrib cga, genattrib g
      WHERE cga.parent_genattrib_id = g.id
)
SELECT array_agg(g.g_id) AS result_array FROM (
  SELECT unnest(citydb_pkg.batch_delete_genericattribs(batch.ids)) AS g_id FROM (
    SELECT array_agg(id) AS ids
      FROM genattrib
      GROUP BY level ORDER BY level DESC
  ) batch
) g;
$$
LANGUAGE sql STRICT;

        FROM surface_geometry sg, geometry g
        WHERE sg.parent_id = g.id
  )
  SELECT citydb_pkg.batch_delete_geometry(id ORDER BY level DESC) INTO result_array
    FROM geometry;

  -- delete appearances not being referenced by geometry any more
  IF clean_apps <> 0 THEN
