Added permutation algorithm