As you already have a working solution, and don’t really have a problem with a specific answer, would you move this question over to softwareengineering.stackexchange.com? I have a proposal for making the thing you want simpler. If you open a new thread there, please comment with a link here. Thanks :) — Zach Young 17 secs ago