Issue #647, fix newline handling edge case.

This issue has been addressed in the reworked commits.