implement path collapsing

This is a follow-on from #57.