a small optimization for the vertical gradients, and use the same log(n) strategy...