Refactor the keymap item code a bit