updated total calculation logic