Updated string permutation code