Walk me through how you would refactor a legacy, tightly coupled codebase to make it more modular and testable.