Circumvent mutation by specs

The tokens are changed by the tests and so a beforeEach setup
would not be possible without moving the creation into a function.
Add headsFor function to state service
Handle change head of an inner node to a leaf