diff --git a/pyhsmm/models.py b/pyhsmm/models.py
index f7974da2bb106302571349f855f844631eca5add..d42be7fb154883fc8c9b779a7fa204696eb710b2 100644
--- a/pyhsmm/models.py
+++ b/pyhsmm/models.py
@@ -187,7 +187,7 @@ class _HMMBase(Model):
     def used_states(self):
         'a list of the used states in the order they appear'
         c = itertools.count()
-        canonical_ids = collections.defaultdict(next(c))
+        canonical_ids = collections.defaultdict(lambda: next(c))
         for s in self.states_list:
             for state in s.stateseq:
                 canonical_ids[state]