added next_permutation function