refactor state manager