Fixing bug in event handler firing