add a wait_for_state sub
add image state code