refactor of event creation and handling