made DiffSq tail-recursive