I assume that this loop is basically a mechanism to retry the query until it returns a value.  Why is that necessary?