Improve event handling and make it work for leap motion controller