closing stream properly