refactor heartbeat