fixed as much as I could in accordance to jshint