reverse foreign keys work, code needs cleanup