change flatten to consolidate