refactor JavaScript to remove anonymous functions