Refactor string functions, fix many defects.

Is that something we should try and fix though and switch to the macro? Presumably people have to manually set __LINE__ etc?