added some event handling code