Describe a time you refactored a complex, poorly written system. What design patterns did you apply and why?