refactor code in .js files