add some checks for existing objects

and tweaks c/o jshint