Refactored JavaScript