formalizer tests and refactoring