initial clustering code