OK, was able to put most of the code back into triangulate, using make_shared