replaced xor with pre-xored flags