Minor refactoring and keyboard events