Refactored js file