Hi @benluoma
I’m finding it difficult to understand your above code.
Perhaps you will find the issue with your code and solve it by simplifying it by breaking it down into steps.
Please add comments to each step to describe what you are doing along the way.
Thanks
E