added clustering code from 2012