Clean up and refactor PermutationsII