Refactored to pass jsHint