More refactoring and JSHint fixes.