Set function performance: build up sets instead of copying and deleting