better detect and handle \r\n