refactoring string utilities function