Unfortunately, I'm still a bit of a "code newbie" in many ways, so I don't have an answer to that particular technical problem. 😳
I think you're on the right track, though, with your train of thought.
I also think that this question is easily explicit enough for StackOverflow. Maybe a bit more whitespace and breaking into paragraphs, but I'd upvote the question over there and answer it if I knew the answer! 😆
We're a place where coders share, stay up-to-date and grow their careers.
We strive for transparency and don't collect excess data.