More JS refactoring stuff