Sort horizontal grid and add tests