... and I decided to open a few beers ...I carried on with my coding and after a while solved the problem... but now I'm sober I can't work out why it works
in reply to Coding while drunk
You're using a dangerous definition of "solved".
What you did was stumble across a combination of stuff that "works", but which you don't understand. That's not solving, that's hiding a problem somewhere else.
Set what you have aside, and rewrite. Unless you can get to something you can understand while sober, you're either not done, or you're in over your head.