Refactored js for jshint