More JS refactoring.