Optimize depth calculus

Some optimizations in the depth calculus