Describe how you would refactor a legacy, tightly coupled codebase into a cleaner, more modular structure.