refactor JavaScript