Fix bug which causes inf loop on \r\n