Further refactor event handling