added permutation code