Remove race condition in keyup event handler

Fix bug #119