Refactor broker into publisher and subscriber

Will be done next.