Additional add.js refactoring.  Added error checking