chaged code for calculations