fix bug on calculation logic