Describe a time when you had to work with a legacy codebase. How did you balance delivering new features with refactoring existing code?