Refactor JS files using modular pattern