More efficient XOR

Simplified logic after comparing to some other merged PRs.