Fixed a bug in the calculation algorithm.