Refactor string functions, fix many defects.

Okay.