Use single output string instead of copying to avoid extra memory use