refactoring the js