Fixed calculation bugs