Bug fix in event handling