Refactoring state code.