rewrite of tbg_calc()

simplified tbg_calc