refactor state