Partial refactoring and clean up of string functions and tests