Fix "glitches" by sorting vertices before filing in the triangles. Also forgot to free a malloc'd pointer.