Reorient algorithm. row = x values, col = y values