rewrite delta calculation