js refactoring 2