Fix errors in calculation