Should you not just write a function for getting the key_transform, and avoid all this duplicate code?