refactoring internalstate