Refactor javascript file