added error checking for viewer code