why using a loop here? I had a hard time understanding the logic flow between the loop, the extraction, error pushing and patching.