Refactor the broadcast code