Implement leaf collapsing