improve event code