refactor state to JSON, added tests