Function heartbeat() has been simplified.