fixed a bug in the calculation