typos.
Added optional parameter for an output file.
Small changes to keep code style conventions.