Reworked the heartbeat code.