Javascript refactoring.