Preserve newlines

Newlines are currently lost, this pull request fixes it for dos and unix newlines.