Fixed bug occasionally causing segmentation faults

Use the proper bound for the loops over the vertices.