fix bug in setup_state