Added code for maxDiff