Fix logic errors that produce incorrect results in specific scenarios.
Fix logic errors that produce incorrect results in specific scenarios.