tidy up codes get_state: using wait?