A slight rewrite to get rid of dirty hacks for formulas/doubles/booleans.