fixed bug in permutation