Commented and re-organized the code. I want this whole thing to stay self-contained in a single HTML file so someone could just File->Save Page As and get something that they can run locally without a network connection and I also don't want a build step while I continue to work on this so I'll be making it easier on myself if there's some kind of organizational structure instead of just throwing everything someplace convenient at random.