Refactored code via JSHint