JS Cleanup

Among other things, this fixes #2685