Refactor broker into publisher and subscriber