I would help to you. First of all you have to make shorter your code that you publish.
You achieve it if you locate the part(s) of your program where you suspect the problem lies.
AFAIK & IMHO approx. 20-40 lines are readable for bug hunting.
Go for it...