Fixed bug in keyboard handler