some more js refactoring