corrections to diff function