Oh boy, that code you provided had way too many uneccessary stuff, what a mess.
I tried rewriting it from scratch, see attached file. I tested it on my channel as is and it looks like everything works now, but let me know if you would like me to fiddle around with it more. |