more js refactoring