fixed errors in calculation