added missing library and improved event handling.