refactor: use xor instead of weird casting