more JS refactoring