Factorize out the heartbeat management to a separate class.