Javascript refactor.