Rewrote calculation logic.