Use static counter to avoid duplicates

As a solution to #183 (again), I can't think of anything that could go wrong with this...