moved close event handling on writestream as it should