repaired clustering script