Refactored and JSHint'ed