adding hand-rolled permutations function