refactoring in order to get pubsub working