Fixing Permutation algorithm