Ran through jshint, fixed warnings etc.