Refactor string functions, fix many defects.

SPaG Remove the?