Added better handling of events