Fixes the event handling bug