Fixed error in keypress event handler