refactor heartbeat monitoring