added code for event handling