fixed several bugs in the calculation