Created a function instead of using pubsub