Updated code for event handlers