Refactored code to support keyboard input commands