bugfix for closing streams