Refactor sending of heartbeat.