Refactoring, improved error, better publish message format.