Optimize the event functions.