changed the data structure for sorted permutations to TreeBag.