Refactor string functions, fix many defects.

@note, or move up above the params?