Refactor string functions, fix many defects.

Yup, order won't change since it's defined in the RDM standard.