refactored to resolve jshint errors