Updated clustering code