clean up key_permutations_name a bit more, and introduce lru_cache to
keep results cached.