Added BeforeDispatchEvent and DispatchEvent