Fixed problem in prepare_surfaces regarding deleting surfaces and merging the remaining curves.