Describe a time when you had to refactor a legacy application to improve its performance and maintainability.