collapse/un-collapse brought into its own function