Refactoring javascript.