Modified so you can call a scan() function multiple times in case of any dynamic loading.  Moved the uniqueness counter up in scope since it looks like it was meant to work that way (although I don't think it was actually causing any problems).