Fixing broken JS when refactoring document javascript earlier