Fixed error in event handling