Refactored Javascript.