Refactor string functions, fix many defects.

Round brackets please.