check if stream is good before writing.
fixed a few style guide violations.