Correct invalid types returned by some formulas. Cleanup code.