Reworked Event Handling code