Normalization is always a good idea. Normalize till it hurts, denormalize until it hurts. Put re-usable things in separate functions and then call them from other actions/functions. You could store the name of the next level as a global parameter in each level then pass the name of the next level into your key_e function each time. If my post needs further explanation or some sample code, I'll be glad to oblige.