It’s hard to say.
The way I would debug this is remove pieces of the code until it works fine. And then add them back one by one. Until you find the one thing that makes it fail 
It’s hard to say.
The way I would debug this is remove pieces of the code until it works fine. And then add them back one by one. Until you find the one thing that makes it fail 