Split long functions into smaller units for better readability.
This function is too long. Refactor following SRP: 1. Extract each logical unit into a separate function 2. Give meaningful function names 3. Clarify parameters and return values 4. Minimize side effects 5. Show before/after code comparison