Refactoring js file