added error checking to pubsub