That’s where Agile Projects come into play.
Build your package incrementally. Management loathes rewriting existing functionality but it needs to be done. After several iterations you’ll get it right.
Real programmers are not Fungable...Lesson 1.
Rebuilding existing functionality, or at least cleaning it out, from the detritus, is something good programers should do on the sly when the opportunity presents itself.....
It’s thankless, and goes unnoticed. But the sublime satisfaction, and making your life easier going forward is ample reward enough.