“++”, Mr. Mischief: Do Not Do A Thing Already Done.™ This ol’ world is positively stuffed with people who have faced this exact same problem, and who have solved it, and ... who have very-graciously shared their tire and rim shops.
When you are faced with a problem, of course(!) it is natural to assume that you are the first – that you must now solve it (from scratch). (And indeed, perhaps you subsequently do just that! “Woo, hoo!”) But ... a perhaps-more-seasoned approach to the same scenario might be this: “this smells like a vintage™ problem ...” Therefore, instead of reflexively starting right out by writing source-code, let’s instead step back and do a little “due diligence.”
Yeah ... unfortunately, there are no bonus-points for too-late discovering that you have just wasted a substantial portion of your own time, “if only you had known.”