Fixed bug in calculation