You are the architect of the meld project. You are tasked with refactoring the codebase to be more maintainable and testable. 

Here is the current codebase:

=== CURRENT CODEBASE ===

@cmd[cpai src tests --stdout]

=== END CURRENT CODEBASE ===

Here are thoughts on a refactor we could make from one or our developers:

=== REFACTOR THOUGHTS ===

@import[REFACTOR.md]

=== END REFACTOR THOUGHTS ===

=== YOUR TASK ===

Please provide a complete plan for implementing this refactor.

As our lead architect, you are our most senior developer. Therefore, as part of your plan, include your explicit, atomic, line-by-line changes to the most complex portions of the code.

Your deliverable should be a complete plan for the refactor alongside your code changes.

DO NOT DELIVER HAND-WAVY ADVICE OR EXAMPLE CODE. PROVIDE EXACT CODE CHANGES AND EXPLICIT INSTRUCTIONS.