XOR? Really? Have not seen this in a long time. ;-) Makes sense here, but please use uppercase XOR for clarity. Same for a few places in this code that use "and" and "or" lowercased. Please prefer && and || in that case.