Modified getHeartRate function