code for integrate clustering into spaghetti