JSLint'd and refactored