Describe a time you had to refactor a poorly structured codebase. What was your approach, and how did you measure success?