refactoring of change_state()