Made the stream implementation more general (file or string streams in the same object)