Cleans up event handler code.