Describe a situation where you had to work with a legacy codebase. How did you approach understanding and improving it?