Move table handling code to formula_manager

Introduce temporaries more aggressively to keep table formulas
smaller, and tweak the order in which trace messages are printed to
keep lines more separate.