removed trailing newlines from log statements
strip newline from line so final element is accurately reproduced
specify UTF8 encoding on input and output