I put duplicate code in the script tag in the body. This is a kluge and I left some comments in that I will remove.
Linted code as much as possible.