Moved the permutation helper into permutations function. (Couldn't access them from each other...)