flatten and duplicates