refactored permutation example