Extract capture loop to capture_loop