Correct some logic errors.