refactoring state cache