Some event handling code and updated tests