updted generic clustering script