Added better event handling