Refactor keypress