rewrite term calculation functions