Optimized isEqual