Added collapseDups() and trimEnds()

TBR

This is going to be useful for some planned developments.