refactor code to get rid of jshint complaints