I don't understand why you need to pass `unnecessary_permutations` recursively. Is it really required?