Describe a time when you had to refactor a legacy codebase. What was your strategy for ensuring no existing functionality was broken?