Added code to calculate some gradient stats.