added permutation algorithm