Improved the horizontal and vertical matching