Complex Nested Looping Subprocess with Error Handling