ran through jshint, fixed some bugs