Added sanitiy check for vertex index bounds.