Refactor permutations. Thanks, Tom Ballinger :)