Refactored to minimize redundancy between horizontal and vertical seams