Refactor pubsub stuff.

Better credentials handling among other things
WIP
WIP