using a better permutation implementation