Added HEARTBEATs to broker and persistence-pg.

Additional changes: Some restructuring in broker and a HEARTBEAT-related fix of the
JSON-producing function in webapp.