fix permutation bug