modified permutations algorithm