Begin refactoring state
Merge branch 'refactorstate'