refactored js file