Unify handling of writes to stdout, and other cleanup.
Merge pull request #6 from jimlloyd/feature/unify-newline-handling

Unify handling of writes to stdout, and other cleanup.