lots of fixes and jshint cleanup