Completely rewrote the JS and HTML to be more DRY.