Changed clustering code, works pretty well.