Fixed bugs in the calculation engine