Optimized the implementation of the Formula class.