Refactored JS using JSHint to validate