Calculation engine code refactored and bug fixed