Datastore: moved state handling implementation to header; doc & style tidy.