changed clustering code