**Problem**
the logic behind `countDuplicates` is invalid because it's doing this:
(incorrect)
```
if(duplicates + e11 == e21)
duplicates = 1;
else
duplicates = 0;
```
Instead of this:
(correct)
```
if(e11 == e21)
duplicates = duplicates + 1;
else
duplicates = duplicates;
```
**Solution**
I'm using an auxiliary variable to fix this
**Alternative solution**
We can also fix it with an array and a loop. But I went for the auxiliary variable for no particular reason.
```
def countDuplicates(field e11, field e12, field e21, field e22) -> u32 {
u32[6] mut duplicates = [0,0,0,0,0,0];
duplicates[0] = e11 == e12 ? 1 : 0;
duplicates[1] = e11 == e21 ? 1 : 0;
duplicates[2] = e11 == e22 ? 1 : 0;
duplicates[3] = e12 == e21 ? 1 : 0;
duplicates[4] = e12 == e22 ? 1 : 0;
duplicates[5] = e21 == e22 ? 1 : 0;
u32 mut count = 0;
for u32 i in 0..5 {
count = count + duplicates[i];
}
return count;
}
```
And btw, I also added an assert to make sure we check for this validation. I've tested this on the playground and on chain on goerli and with this changes it works correctly.