Added code for permutations