Refactor code, add comments to Broker.php