Describe a time you had to refactor a legacy codebase to improve modularity and testability. What was your strategy?