added validation for grid size