Fixed bug closing stream buffer