Fix closing stream