fixed bug with infinite loop when not enough permutations