Fixed the grid query to more accurately calculate the size of the grid