Added break when max difference is zero. Added factor to limit how often caclulateMaxDifference is run.