Fix a bug in how events are handled