Refactor the logic and add XOR boolean operator