save state in db