Improve event related code.
Misc changes