changed outfile stream from ReadStream to WriteStream