Removal of repeated things and rearrangement