Refactor JavaScript functions. Make work.