Working version of match where xor is working but processing taking too long