Grid sort