Added collapseDuplicates