Lots of fixes thanks to jshint