Fixed bug when calculating diff