fixed a calculation crash bug. fixed a memory leak with intermediate value.