optimized function unique subsets