Refactor JS file