small refactor and fix for jshint