fixed some errors in calculation