JavaScript Refactor