cleaned up permutation script