Extracted `chain` to a helper function, and wrapped with a try/catch block.
Extracted `chain` to a helper function, and wrapped with a try/catch block.