consolidate collapse code