added try/catch, jshint compliance