Refactor and move function to StringUtils, review fixes