Fixed some bugs uncovered by jshint