added diffN and perDiff functions