Fixed counting error when considering duplicates