refactored all calculations