Fix loop in getPermutations()