functions for working with permutations