Added a collapse() function