     delete_agg_end,
     post_block
   FROM
-    citydb_pkg.delete_fkeys_by_ids($1, $3);
+    citydb_pkg.create_ref_to_array_delete($1, $2);
 
   -- FOREIGN KEY which cover same columns as primary key
-  post_block := post_block || citydb_pkg.delete_parent_by_ids($1, $3);
+  post_block := post_block || citydb_pkg.create_ref_to_parent_array_delete($1, $2);
   
   -- if there is no FK to clean up IDs can be returned directly with DELETE statement 
   IF post_block = '' THEN

$$
LANGUAGE plpgsql STRICT;

-- creates code block to delete referenced parent entries
CREATE OR REPLACE FUNCTION citydb_pkg.delete_parent_by_id(
  table_name TEXT,
  schema_name TEXT DEFAULT 'citydb'
  ) RETURNS TEXT AS
$$
DECLARE
  rec RECORD;
  parent_block TEXT := '';
BEGIN
  FOR rec IN (
    SELECT 
      f.confrelid::regclass::text AS parent_table,
      f.confrelid::regclass::text AS parent_table_short
    FROM
      pg_constraint f,
      pg_constraint p
    WHERE
      f.conrelid = ($2 || '.' || $1)::regclass::oid
      AND p.conrelid = ($2 || '.' || $1)::regclass::oid
      AND f.conkey = p.conkey
      AND f.contype = 'f'
      AND p.contype = 'p'
      AND f.confdeltype = 'a'
  )
  LOOP
    -- create array delete function for parent table
    PERFORM citydb_pkg.create_delete_function(rec.parent_table, rec.parent_table_short, $2);

    -- add delete call for parent table
    parent_block := parent_block
      || E'\n  -- delete '||rec.parent_table
      || E'\n  PERFORM gen.delete_'||rec.parent_table_short||E'(deleted_id);\n';
  END LOOP;

  RETURN COALESCE(parent_block,'');
END;
$$
LANGUAGE plpgsql;

  rec RECORD;
BEGIN
  FOR rec IN (
    SELECT * FROM citydb_pkg.query_ref_fk($1, $2)
  )
  LOOP
    IF vars IS NULL THEN
