refactored pubsub module