added null check for grid