Refactor permutations