fixed some calculation errors