Split a Large Function into Smaller Units

Break a large function into smaller, focused functions with clear responsibilities.

category:refactoring
modularization
clean-code
0

Prompt

This function is too large and does too many things.
  
  Refactor it by:
  - Identifying logical sub-steps.
  - Extracting them into small, pure functions with good names.
  - Keeping the original function as an orchestrator that calls the smaller ones.
  - Avoiding duplication and side effects where possible.
  
  Function:
  
  [Paste function here]