Refactor event system