Refactor loops into wait_for_status method