optimize event handler