Refactored InputMap event handling code