make sure the end events are emitted as the final events. fix #616