Almost a complete rewrite later, everything (in index.html) works and makes more sense to me.