updated difference function