Supported key input and refactored a little