removed duplicate code from keyboard listener.