Refactor and add support for string formulas