Fix issue with too early 'end' event