added pubsub example and fixed a bug