Describe a scenario where you had to refactor a legacy codebase. How did you ensure you did not introduce regressions?