fixed arrayoutofbounds exception if some input lines are less than gridsize