refactored and fixed jshint errors