fix "undefined variable" and "variable out of scope" issues identified by jshint