Move writing of state id to state into assigning an id

* This is so that when setting a limit on the state space size we
  still have a states successors mapped to an id
* Unit tests pass