Fixed creation of grid to work with non-sqaure sizes