Fix bug with call flush in event listeners