clean up events code a bit