Refactor broker into publisher and subscriber

Commented code