Drastic fixes and Rewrites almost always consist of three things:
1. Writing tests to ensure functionality
2. Writing an interface or shimming the existing functionality to redirect control flow
3. Implementing and testing the rewritten functionality/improvements
Obviously you can't do it everywhere, but life is much better when (2) was done up front.