Updated with second difference function