JSLint validation and refactoring