The title may sound a bit weird from the guy who thinks you should really re-use code, but I assure you that these things are completely possible to combine.
You probably have had the same experience more than once. You build a quick, hacky prototype to show something off, or to try out if something works. Then, rather than throwing the prototype out and plan things properly you use it as a basis for a real project.
This is only one of the cases where you start building on an unstable base. Then you end up bolting stuff on and hacking around problems as you don't really want to touch code that is technically working.
Do yourself a favor, don't use that code, just throw it out... Do it right away.
You may even have some code like that in a shipping product somewhere. If you do there is nothing wrong with just throwing it out. Provided that the parts of it are well encapsulated you should just be able to pull out the good parts and throw away the rest.
You may think I'm crazy, you may think you don't have the time to fix things, you may think it is a waste of money.... Trust me, pushing the cost into the future just makes it worse.
For example, the single most important Snowflake release for code quality, stability and performance to date in my opinion is 2.0 where we threw out a bunch of old code and re-wrote it. It was a massive task, but it was definitely worth it as in my mind it made it take a leap 10 years ahead of the competition in terms of just pure technical quality.
It was of course a risk, how much time would we spend on it? Would it even be feasible possible to do? Wouldn't we miss all that crazy stuff we spent hours on during a caffeine-infused night in 2008?
Based on the last few years I must say that it was clearly the right decision. It would not have been possible without the team being so incredibly experienced with doing what we do best.
As someone who has over the last 20 years written thousands of lines of code that now lives at /dev/null I must say that there are few things more liberating than deleting code. Less code almost always mean less problems.
So, build that quick prototype, take the experience... Then chuck it in the bin and start on planning out your real implementation.