updated javascript so that all code is wrapped within an error handler, so that output can be cleaned up