fixed bug in event handling