Fixed stream.close bug