Moved state_change to misc.c to start using it in main.c, too