event handling refactor