added optional input stream argument
added optional output stream argument
added output file option