reworked the event handler