Refactoring Javascript to pass JSLint