Refactor string functions, fix many defects.

Drop the << to this line and align.