Added calculation of heartbeat