Refactor string functions, fix many defects.

Can we have some round brackets please.