Its not straightforwardly easy to know what causes your error as it's not possible to run your code (it includes data only you have...)
Here is a guide on how you can approach that.
I was asking about the relevance as it seems you have one complaint , but two unrelated codes, I was attempting to identify the problematic code. I hope you understand my intentions.