Fixed newline handling to support \n and \r\n