Make more readable and add comments
Rename do_mask to xor