fixed some of the calculation bugs