Fixed some logic errors

fixed some minor math errors.