Added listeners for keyboard. Slight refactoring.