clean up and use the correct end event for streams