added validation to ensure the user input is a number and the grid dimension is not zero