more refactoring for the calculation