Added a DSL for formulas and some refactoring