One suggestion that I just thought about...
If you're checking voiced users (or voiced and regular users), you should use one of these (depending if you want just voiced or voiced & regular:
$nick($chan,0,v,o)
$nick($chan,0,rv,o)
The reason is that if you don't tell it to ignore opped users, you'll also count all ops who are also voiced. $vnick also counts ops that are voiced.
You can try it out. Voice a couple of ops so that they are +ov and then check the number of voiced users in the channel. It won't match the number who are just voiced.