Better collapsing. Too slow; about to optimize.
Optimized collapsing. Works fine but doesn't actually produce good results.