Code clarity improvements in heartbeat handling