fixed bug in calculation