Refactor string functions, fix many defects.

Yup, done