Fix some logic errors.