Adding test of heartbeat functionality
Code to fix Flags class.

And other small changes.