js refactoring