Check type in __eq__() and __ne__(), simplify code