Calculation logic