Rename state with entity, and reparent orphaned entity data

Fixes #599.

Ready for discussion and review. It's pretty complex -- parallel reference to http://flapjack.io/docs/1.0/development/DATA_STRUCTURES/ is assumed, and the merge case especially gets fairly complicated depending on the possible orders of events.