Improved handling of formulas