Plan a refactor you can ship safely: what's wrong with the code now, the target design, small steps that keep behavior unchanged, tests to add first, and how to roll each step back.