Like mentioned above, every new trial will bring some experience in the end so I wouldn't see it as a waste of time. If that was the case, I would be crying a lot over all the re-factoring I did recently
But right now, the problem is maybe you changed too much thing without knowing the impact of that change. In assembler, this can sometime be lethal (I experienced it many time ;;^_^). My suggestion, although abstract, would be that you first roll back to a previous version that work and do the operation on a few variables that you know would have a visual impact right away if they're not working properly. During that phase, don't focus on the code sharing but on the variable sharing only, which seem to be the one causing issue. Once you figure out the cause, you can reproduce the same thing with another group of variable. You should do it gradually since maybe you did some miss (typo or something) and now you cannot figure out where it is. Save every interim revision until the end, just in case something goes wrong during the process.
I had a few issue like that when converting the FT driver. I was doing it in one shot and couldn't figure out where did I miss. Doing it gradually should help.
It may not be the answer that you're looking for but maybe the process could help in the end figuring out what went wrong.