jshint fixes, misc refactoring