Add permutation generating logic