Moving functions into formulas.py