refactor event dispatch and demo