fixing the XOR, finaly, adding unit tests, some simplifications