Add event handling function