(main_set_state) More refactoring