refactor and added pubsub