Tidy up handling of newlines

[#62999446]