Refactor keybinding and add detailed comments