simplified implementation of permutations.