Find repeated code patterns and extract into common functions.
Find and remove duplicates in this code: 1. Identify places with repeated logic 2. Extract into common utility functions 3. Use generics/type parameters 4. Show code after applying DRY 5. Write tests for extracted functions