Let instances finish stopping and shutting down before checking state

Added loop to wait for instance to finish stopping and shutting down
before trying to determine the instance state