Conditional calculations are not correct