Refactored key mappings so that it is more flexible.