factor out some string functions