refactoring js file