refactor event handlers