An implentation of the difference calculation....I hope this is correct.