response to comments
A commenter says:
You've listed the ways you can improve the code in the question. Why have you come to us for help when you know how it can be improved? It seems like you meant to answer your own question when posting, but didn't for some reason.
Note that the voting arrow has a title attribute that reads "This question shows research effort; it is useful and clear" - I am attempting to demonstrate the research efforts I have already made in alignment with the explicit builtin direction of the site. I want feedback on the things I am not yet aware of or am missing. Perhaps my ideas on how it can be improved are wrong.