added pub/sub, error handling fixed