The problem has nothing to do with variable declaration as far as I can see.

If you only want unique values why are you testing if the count is 0?

Surely you should be checking for a count of 1?