More correct parsing of \r\n and \n line endings