updated calculation logic