Simple implementation of collapse_singles()

Still needs better testing.