Added debug messages to the event handler