Robustify heartbeat code