Fix grid size>9 + problem while checking rectangle validity