Fixed an error when calculating the vertical distance between cells