Add waitFor helper.  Fix apparent typo in state handling.