How many times have you done this?
What now? Time to step back, write the general solution, rework everything, fix the corner cases, check for error conditions, change all places that do it the old way to do it the new way, check for leaks and clean up the code. Now you are done and ... nothing works.
By this time, you've blown away the old code so you have no idea what the problem is. Did it ever work at all? What did I change? Was I doing a Billy?