[UPDATE] cleaned-up code. Multiple output streams. Error handling.
[UPDATED] changed output file names. TODO.